How to create Toast Notification with custom icon and custom app name? - c#

I'm trying to create a Windows Toast Notification with .Net C#. While this, I would like to change the notification icon and the app name in the attribution area (header) of the notification.
I'm able to place a notification with a custom "App name" like shown here:
I do this with this code:
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("Title"));
stringElements[1].AppendChild(toastXml.CreateTextNode("Message"));
ToastNotification toast = new(toastXml);
ToastNotificationManager.CreateToastNotifier("App name").Show(toast);
But I don't find a solution, how to place an icon left from "App name".
The solution can't be to modify the toast on a different way, since it only changes the visual or action elements. But not the attribute area:
How can I show an icon in the attribute area?

To set the icon in the attribution area you can set it directly.
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("Title"));
stringElements[1].AppendChild(toastXml.CreateTextNode("Message"));
ToastNotification toast = new(toastXml);
// here you set your icon
toast.attribution.icon = new ToastImageSource("path to your image");
ToastNotificationManager.CreateToastNotifier("App name").Show(toast);
To set the icon in the title you can change the created toast.
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("Title"));
stringElements[1].AppendChild(toastXml.CreateTextNode("Message"));
ToastNotification toast = new(toastXml);
// Here you can change the visual element of the toast
// don't know which image will be correct. Can't test at the moment
toast.Visual.TileLarge.HintRemoveMargin = true;
toast.Visual.TileSmall.HintRemoveMargin = true;
toast.Visual.TileMedium.HintRemoveMargin = true;
toast.Visual.TileLarge.Branding = ToastBranding.Logo;
toast.Visual.TileSmall.Branding = ToastBranding.Logo;
toast.Visual.TileMedium.Branding = ToastBranding.Logo;
toast.Visual.TileLarge.AppLogoOverride = new ToastAppLogo();
toast.Visual.TileSmall.AppLogoOverride = new ToastAppLogo();
toast.Visual.TileMedium.AppLogoOverride = new ToastAppLogo();
toast.Visual.TileLarge.AppLogoOverride.Crop = new ToastAppLogoCrop(0, 0, 1, 1);
toast.Visual.TileSmall.AppLogoOverride.Crop = new ToastAppLogoCrop(0, 0, 1, 1);
toast.Visual.TileMedium.AppLogoOverride.Crop = new ToastAppLogoCrop(0, 0, 1, 1);
toast.Visual.TileLarge.AppLogoOverride.Source = new ToastImageSource("file:///C:/path/to/your/icon");
toast.Visual.TileSmall.AppLogoOverride.Source = new ToastImageSource("file:///C:/path/to/your/icon");
toast.Visual.TileMedium.AppLogoOverride.Source = new ToastImageSource("file:///C:/path/to/your/icon");
ToastNotificationManager.CreateToastNotifier("App name").Show(toast);
Additionally you can set an appLogoOverlay which is displayed in the title area
// get hte ToastGeneric toast content
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastGeneric);
// here you get the visual element of the toast
XmlNodeList toastVisualElements = toastXml.GetElementsByTagName("visual");
// to add an icon you need app logo overlay
XmlElement appLogoOverlay = toastXml.CreateElement("appLogoOverlay");
// here you set the source of the overlay
appLogoOverlay.SetAttribute("src", "path to your icon");
// here you can add style attributes
appLogoOverlay.SetAttribute("hint-crop", "circle");
toastVisualElements[0].AppendChild(appLogoOverlay);
var stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("Title"));
stringElements[1].AppendChild(toastXml.CreateTextNode("Message"));
ToastNotification toast = new(toastXml);
ToastNotificationManager.CreateToastNotifier("App name").Show(toast);

Related

I am trying to insert hyperlink to another website in pdf

In FormField "HH" i am trying to make text as link, but it is readed only as string text, it is not clickable.
I use Aspose.Pdf v.11.6.0.
var doc = new Aspose.Pdf.Document(pdfFileStream);
var pdfForm = new Aspose.Pdf.Facades.Form(doc);
pdfForm.FillField("Name", model.Name.ToUpper());
pdfForm.FillField("ISOS", model.NumberISOS.ToUpper());
pdfForm.FillField("Info", dateInfo);
pdfForm.FillField("HH", "http://www.somewebsite.com");
I use this code:
Page page = (Page)doc.Pages[1];
var text = new TextFragment("index");
text.Position = new Position(200, 300);
Aspose.Pdf.WebHyperlink link = new
WebHyperlink("www.google.com");
text.Hyperlink = link;
page.Paragraphs.Add(text);
but new Position(200, 300); values not responding.
Here is my solution, because position does not work, i move the link with margins. This worked for me.
Page page = (Page)doc.Pages[1];
var text = new TextFragment("LINK");
text.Position = new Position(300, 300);
Aspose.Pdf.WebHyperlink link = new WebHyperlink("www.google.com");
text.Hyperlink = link;
text.Margin.Left = -48;
text.Margin.Top = 687;
text.Margin.Bottom = -150;
text.TextState.Underline = true;
text.TextState.FontSize = 11;
text.TextState.ForegroundColor = Aspose.Pdf.Color.DeepSkyBlue;
text.TextState.BackgroundColor = Aspose.Pdf.Color.White;
page.Paragraphs.Add(text);

embedded image in Xamarin Forms using c# [duplicate]

This question already has answers here:
Xamarin Forms - how to add background image to a content page
(2 answers)
Closed 5 years ago.
Guys Im having a little trouble trying to make an image the background for a certain page. Im trying to do it via the embedded method mentioned here:https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/#Embedded_Images
.For some reason when I run the app, it crashes. I think something went wrong at 'BackgroundImage =' line cause I kinda guessed when I did that. When I comment out that line, the app loads fine, just without the background image. I used build action = content and copy to output directory as settings...
public class LoginPage : ContentPage
{
Entry emailBox = new Entry();
Entry passwordBox = new Entry();
Button createAccount = new Button();
Button forgotPassword = new Button();
StackLayout layout = new StackLayout();
Image embeddedImage = new Image { Source = ImageSource.FromResource("Charity.Properties.hands-426x640.jpg") };
public LoginPage()
{
Title = "Login";
BackgroundColor = Color.LightPink;
BackgroundImage = "Charity.Properties.hands-426x640.jpg";
emailBox.Placeholder = "email";
emailBox.BackgroundColor = Color.LightPink;
emailBox.PlaceholderColor = Color.HotPink;
passwordBox.Placeholder = "password";
passwordBox.BackgroundColor = Color.LightPink;
passwordBox.PlaceholderColor = Color.HotPink;
passwordBox.IsPassword = true;
createAccount.Text = "create an account";
createAccount.TextColor = Color.HotPink;
createAccount.Font = Font.SystemFontOfSize(NamedSize.Medium);
createAccount.BorderWidth = 0;
createAccount.HorizontalOptions = LayoutOptions.Center;
createAccount.VerticalOptions = LayoutOptions.CenterAndExpand;
forgotPassword.Text = "recover password";
forgotPassword.TextColor = Color.HotPink;
forgotPassword.Font = Font.SystemFontOfSize(NamedSize.Medium);
forgotPassword.BorderWidth = 0;
forgotPassword.HorizontalOptions = LayoutOptions.Center;
forgotPassword.VerticalOptions = LayoutOptions.CenterAndExpand;
layout.VerticalOptions = LayoutOptions.End;
layout.BackgroundColor = Color.LightPink;
layout.Children.Add(emailBox);
layout.Children.Add(passwordBox);
layout.Children.Add(createAccount);
layout.Children.Add(forgotPassword);
Content = layout;
}
}
This works, after much trial and error I only needed to add the image to both .Droid(drawable) and .iOS(resources) folders. I had not added it to the iOS folder previously, hence it kept crashing when I ran on an iOS simulator.
Image image = new Image();
public LoginPage()
{
Title = "Login";
BackgroundImage = "hands426x640.jpg";}

Children.Add() in Xamarin Forms

im really new to c# and Xamarin Forms but can someone please explain to me why I'm getting an error in the last line of code below ?
Visual Studio is indicating a curly red underline on the word Children on the last line of this code indicating that there is some syntax error but I don't see why that is an error since I'm just accessing a member of the class ....
var content = new ContentPage();
content.Title = "Appuler";
Label CompanyName = new Label();
CompanyName.HorizontalTextAlignment = TextAlignment.Center;
CompanyName.Text = "Test";
Button NextPage = new Button();
NextPage.Text = "Next Page";
NextPage.Font = Font.SystemFontOfSize(NamedSize.Large);
NextPage.BorderWidth = 1;
NextPage.HorizontalOptions = LayoutOptions.Center;
NextPage.VerticalOptions = LayoutOptions.CenterAndExpand;
content.Content = new StackLayout();
content.Content.VerticalOptions = LayoutOptions.CenterAndExpand;
content.Content.Children.Add(CompanyName);
Refactor the last few lines to the following
var layout = new StackLayout();
layout.VerticalOptions = LayoutOptions.CenterAndExpand;
layout.Children.Add(CompanyName);
content.Content = layout;
ContentPage.Content does not have that Children property as it is a View. StackLayout, however does have a Children property that can be accessed.
populate the layout control's accessible properties and then assign it to the Content property of the ContentPage.

track google chorme URL

I want to get url of all tabs I found this code
this code give me tabs title only please tell me how I get all tabs url
var automationElements = AutomationElement.FromHandle(proc.MainWindowHandle);
// Find `New Tab` element
var propCondNewTab = new PropertyCondition(AutomationElement.NameProperty, "New Tab");
var elemNewTab = automationElements.FindFirst(TreeScope.Descendants, propCondNewTab);
// Get parent of `New Tab` element
var treeWalker = TreeWalker.ControlViewWalker;
var elemTabStrip = treeWalker.GetParent(elemNewTab);
// Loop through all tabs
var tabItemCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem);
foreach (AutomationElement tabItem in elemTabStrip.FindAll(TreeScope.Children, tabItemCondition)) {
var nameProperty = tabItem.GetCurrentPropertyValue(AutomationElement.NameProperty);
Debug.WriteLine("title: " + nameProperty.ToString());
}

Coding4Fun InputPrompt style text box

I'm trying to style the Coding4Fun InputPrompt control to set a border on the textbox element and change the unselected colour in code.
I've not been able to find any examples, and visual studio doesn't recognise the control properly (InputPrompt is displayed in red with no intellisense, but the project runs fine).
I've managed to set some colours and update the buttons, but no success on the textbox.
Can anyone point me in the right direction please?
Here is what I have so far:
var input = new InputPrompt
{
Title = "Title",
Message = "My Message",
IsCancelVisible = true,
Background = new SolidColorBrush(Color.FromArgb(0xCC, 0x00, 0x00, 0x00)),
Foreground = new SolidColorBrush(Colors.White)
};
input.Completed += input_Completed;
input.InputScope = new InputScope
{
Names = {new InputScopeName() {NameValue = InputScopeNameValue.TelephoneNumber}}
};
foreach (var button in input.ActionPopUpButtons)
{
button.Foreground = new SolidColorBrush(Colors.White);
button.BorderBrush = new SolidColorBrush(Colors.White);
button.Margin = new Thickness(0,5,0,0);
}
input.BorderThickness = new Thickness(5.0);
input.Show();

Categories