Windows Lock Screen, add Text programmatically - c#

I want to display custom text or control on the Windows 10 Lockscreen, when I click on a button. I tried it with an UWP Application.
My goal is something like this:
And the Code I tried:
ToastContent content = new ToastContent()
{
//Duration = ToastDuration.Long,
Scenario = ToastScenario.Reminder,
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Attribution = new ToastGenericAttributionText()
{
Text = "Hello World"
}
}
},
Actions = new ToastActionsCustom()
{
Buttons = {
new ToastButton ("mycontent", "myargs")
}
}
};
var notification = new ToastNotification(content.GetXml());
ToastNotificationManager.CreateToastNotifier().Show(notification);
Also I saw this post and tried it of course, but it wasnt helpfull: Windows Lock Screen display text programmatically C#
Maybe you could help me to achive my goald
I thank you in advance

The screenshot you post above is smtc that used to show current playing music, for enable it you need to enable the app Background Media Playback, but it only use to show the media info, it can't use to share custom info like you mentioned scenario.
For your scenario, the better way is register your app LockScreen capability like the following.
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="xxxxx.UWP.App">
.......
<uap:LockScreen BadgeLogo="Assets\BadgeLogo.png" Notification="badgeAndTileText"/>
</uap:VisualElements>
</Application>
</Applications>
And set the app as main toast in the lock screen Setting page -> Personalization -> lock screen -> Choose one app to show detailed status on the lock screen If you have resisted the app, it will show in the apps list.
Code Sample
private void Button_Click(object sender, RoutedEventArgs e)
{
TileContent content = new TileContent()
{
Visual = new TileVisual()
{
LockDetailedStatus1 = "Hello world",
TileWide = new TileBinding() { }
}
};
var notification = new TileNotification(content.GetXml());
TileUpdateManager.CreateTileUpdaterForApplication().Update(notification);
}

Related

Tab view not working right on UWP Windows UI Library

I am making an app for UWP on Visual Studio that uses the Windows UI Library for the tab view component. I was following the documentation and it gives the following code to use:
xaml:
<muxc:TabView AddTabButtonClick="TabView_AddTabButtonClick" TabCloseRequested="TabView_TabCloseRequested"/>
c#:
// Add a new Tab to the TabView
private void TabView_AddTabButtonClick(muxc.TabView sender, object args)
{
var newTab = new muxc.TabViewItem();
newTab.IconSource = new muxc.SymbolIconSource() { Symbol = Symbol.Document };
newTab.Header = "New Document";
// The Content of a TabViewItem is often a frame which hosts a page.
Frame frame = new Frame();
newTab.Content = frame;
frame.Navigate(typeof(Page1));
sender.TabItems.Add(newTab);
}
// Remove the requested tab from the TabView
private void TabView_TabCloseRequested(muxc.TabView sender, muxc.TabViewTabCloseRequestedEventArgs args)
{
sender.TabItems.Remove(args.Tab);
}
I added that code to my project and and at first glance it looks normal.
However when try to interact, there are problems. I can only create a new tab if I click at the very bottom edge of the " + " icon. I also cant exit any tabs or interact with them.Here's a gif of my problem:
https://im7.ezgif.com/tmp/ezgif-7-565b1f0b4531.gif
Does anybody have a fix for this?
Thanks for any help
You need to create a TabStripHeader and TabStripFooter.
TabStripHeader's children is Grid and set name it to ShellTitlebarInset,
TabStripFooter's children is Grid and set name it to CustomDragRegion
and set background to Transparent for both.
Use CustomDragRegion as Title Bar.
Like Example:-
<muxc:TabView>
<muxc:TabView.TabStripHeader>
<Grid x:Name="ShellTitlebarInset" Background="Transparent" />
</muxc:TabView.TabStripHeader>
<muxc:TabView.TabStripFooter>
<Grid Grid.Column="3" x:Name="CustomDragRegion" Background="Transparent" />
</muxc:TabView.TabStripFooter>
</muxc:TabView>
And C# Example:-
public MainPage()
{
this.InitializeComponent();
var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
coreTitleBar.ExtendViewIntoTitleBar = true;
coreTitleBar.LayoutMetricsChanged += CoreTitleBar_LayoutMetricsChanged;
Window.Current.SetTitleBar(CustomDragRegion);
}
private void CoreTitleBar_LayoutMetricsChanged(CoreApplicationViewTitleBar sender, object args)
{
if (FlowDirection == FlowDirection.LeftToRight)
{
CustomDragRegion.MinWidth = sender.SystemOverlayRightInset;
ShellTitlebarInset.MinWidth = sender.SystemOverlayLeftInset;
}
else
{
CustomDragRegion.MinWidth = sender.SystemOverlayLeftInset;
ShellTitlebarInset.MinWidth = sender.SystemOverlayRightInset;
}
CustomDragRegion.Height = ShellTitlebarInset.Height = sender.Height;
}
Note: To ensure that the tabs in the title bar are not occluded by shell content, you must account for left and right overlays. In LTR layouts, the right inset includes the caption buttons and the drag region. The reverse is true in RTL. The SystemOverlayLeftInset and SystemOverlayRightInset values are in terms of physical left and right, so reverse these too when in RTL.
Click Here for More Information

Windows 10 Notification from desktop APP : OnActivated event

I create a desktop app c# where i use some references :
using Microsoft.Toolkit.Uwp.Notifications;
using System.Windows;
using Windows.ApplicationModel.Activation;
using Microsoft.QueryStringDotNET;
And where i added some reference related to UWP application :
- Windows.System
- Windows.UI
- Windows.data
- Windows.Foundation
- Windows.ApplicationModel
Then i created a simple procedure to create and show my toast notification with the followin code :
private void Button_Click(object sender, RoutedEventArgs e)
{
var toastContent = new ToastContent()
{
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = "Surface Launch Party"
},
new AdaptiveText()
{
Text = "Studio S / Ballroom"
},
new AdaptiveText()
{
Text = "4:00 PM, 10/26/2015"
}
}
}
},
Actions = new ToastActionsCustom()
{
Inputs =
{
new ToastSelectionBox("status")
{
DefaultSelectionBoxItemId = "yes",
Items =
{
new ToastSelectionBoxItem("yes", "Going"),
new ToastSelectionBoxItem("maybe", "Maybe"),
new ToastSelectionBoxItem("no", "Decline")
}
}
},
Buttons =
{
new ToastButton("RSVP", "action=rsvpEvent&eventId=63851")
{
ActivationType = ToastActivationType.Foreground
},
new ToastButtonDismiss()
}
},
Launch = "action=viewEvent&eventId=63851"
};
Windows.Data.Xml.Dom.XmlDocument xmldoc = new Windows.Data.Xml.Dom.XmlDocument();
xmldoc.LoadXml(toastContent.GetContent());
var toast = new ToastNotification(xmldoc);
toast.Activated += OnActivated1;
// Create the toast notification
//var toastNotif = new ToastNotification(xmlDoc);
// And send the notification
ToastNotificationManager.CreateToastNotifier("Test").Show(toast);
Now my problem is that i don't know how to retrieve the item i selected in the list :-(
I created an procedure based toast.Activated event :
void OnActivated1(ToastNotification sender, object e)
{
var toastActivationArgs = e as ToastNotificationActivatedEventArgs;
}
With this event, i can retrieve the argument (to know the button i clicked on) but getting the UserInput thanks to the class "ToastNotificationActivatedEventArgs" seems to be not possible...
Do you know if it's possible ? Is it a limitation of using reference UWP in a desktop app ?
Thank you very much !
Vincent
If you're building a Win32 Desktop app using the Desktop Bridge, you currently cannot use inputs and selection boxes in your toast, as there's no way to retrieve the input.
If you're building a normal Win32 app, you must set up a COM server to handle activation, which will include the inputs that the user selected. This quickstart explains how to set this up for normal Win32 apps. Plus, this will also allow your toasts to persist in Action Center, so if the user missed the popup, they can still access your toast from Action Center.
thank you for your answers.
The issue i have with my sub OnActivated :
void OnActivated1(ToastNotification sender, object e)
{
var toastActivationArgs = e as ToastNotificationActivatedEventArgs;
}
is that the "e" object is recocgnized as a Windows.UI.Notifications.ToastActivatedEventsArgs and not as "ToastNotificationActivatedEventArgs" from Windows.ApplicationModel.Activation (where the properties Kind, UserInput.. should be very useful for me to get the content of selected item).
In my OnActivated1 sub, the var toastActivationArgs value equals to null because it cannot be converted to ToastNotificationActivatedEventArgs.
During my test the e.arguments equals to string "action=rsvpEvent&eventId=63851" but there is no XML returned. This is the only property available of the object e. (but this is useful to get the button where i clicked on)
I'm going to check the link from Andrew Bares to try to setup a COM server but i can see that's in c++ language..
Thank you !
The ToastNotificationActivatedEventArgs e.Arguments should be an xml string with what you need ready to parse.
First look at the string and see if it has what you need. Then go about using XMLReader or something to parse it.
Could you post the string you get?

How to use TestStack.White to click the button under the menu

I tried to use white to click the new project button, I try using the below code, but it can not work, anyone can help me?
public void Notepad()
{
Application app = Application.Launch("C:\\Program Files (x86)\\SourceMonitor\\SourceMonitor.exe");
Window window = app.GetWindow("SourceMonitor", InitializeOption.NoCache);
Button button = window.Get<Button>("File");
button.Click();
app.Kill();
}
I already figured out how to do it, below is the correct code:
public void Notepad()
{
// Arrange
Application app = Application.Launch("C:\\Program Files (x86)\\SourceMonitor\\SourceMonitor.exe");
Window window = app.GetWindow("SourceMonitor", InitializeOption.NoCache);
// Act
MenuBar menuBar = window.MenuBar;
menuBar.MenuItem("File","New Project").Click(); ; //can use any other search criteria as well.
}

Change application default tile in runtime on Windows 10 UWP

I need to change color of application tile to accent color.
On wp8 I used ShellTile class and change icon to transparent, so this solution works.
But on Windows 10 ShellTile is missing. There is another possible method using TileUpdateManager, but it's changing icon for LiveTile, not for default Tile Icon.
This code works for updating LiveTile, but not for default icon.
TileContent content = new TileContent()
{
Visual = new TileVisual()
{
TileMedium = new TileBinding()
{
Content = new TileBindingContentAdaptive()
{
BackgroundImage = new TileBackgroundImage()
{
Source = new TileImageSource("Assets/Tiles/FlipCycleTileMediumOp.png")
}
}
}
}
};
TileUpdateManager.CreateTileUpdaterForApplication().Update(new TileNotification(content.GetXml()));
And this kinda resolve the problem, but when I disable "live tile" option, icon returns to default.

WPF: Switching window styles

I have a program that has some buttons, one of them is used to switch "Themes".
There are two themes, one is the normal Windows theme and the other is called Style2.
This is how I tried the switching
private bool UsingWindowsStyle = true;
private ResourceDictionary Style2= new ResourceDictionary() { Source = new Uri("/...;component/Resources/DefaultStyles.xaml", UriKind.RelativeOrAbsolute) };
private void SwitchButton_Click(object sender, RoutedEventArgs e)
{
if (UsingWindowsStyle)
{
Resources.MergedDictionaries.Add(Style2);
UsingWindowsStyle = false;
}
else
{
Resources.MergedDictionaries.Remove(Style2);
UsingWindowsStyle = true;
}
}
My problem is, when I use this program, and press this Button, this is what happens:
Window Opened Program operating normally with Windows theme.
SwitchButton First Click Program changes visuals to the Style2 theme. All the program's buttons operating normally.
SwitchButton Second Click Program reverts back to Windows theme, but all the buttons in the program seize to work.
Points to Consider
The program does not throw any exceptions at this point.
Debugging the code, it seems that after the second click, the program does not enter the SwitchButton_Click method.
I tried readding the Click EventHandler but with no use.
SwitchButton.Click += new RoutedEventHandler(SwitchButton_Click);
Thanks in advance for your help.
I would suggest that you are trying too hard. All you need to do is to change the Style on the Window itself. Leave the dictionaries alone. :-)
Here is an example that changes a windows style when you click from the list of available styles.
My command boils down to
//Here I am changing the style on the window
NewWindow.Style = ((StyleDetailsViewModel)x).Style;
NewWindow.Show();
with various input data
public StylingViewModel(Func<string, Style> findStyle)
{
Styles = new StyleDetailsViewModel[]
{
new StyleDetailsViewModel
{
Name = "None",
Description = "Completely remove all styling and show the raw NavigationWindow including default navigation elements",
WindowStyleNone = false,
Image = "\\Resources\\WindowStyleNone.png"
},
new StyleDetailsViewModel
{
Name = "PlainWindow",
Style = findStyle("PlainWindow"),
Description = "Hides the navigation elemetns of the NavigationWindow to make it look just like a normal window",
WindowStyleNone = false,
Image = "\\Resources\\WindowStylePlain.png"
},
new StyleDetailsViewModel
{
Name = "Windows 7",
Style = findStyle("Win7NavigationWindow"),
Description = "Uses glass effects to create a window that looks almost identical to the control panel from Windows 7.",
WindowStyleNone = false,
Image = "\\Resources\\WindowStyleWin7Nav.png"
},
and
this.DataContext = new StylingViewModel(x => (Style)this.FindResource(x));
Also beware of certain Window properties that can only be set before the window opens, such as WindowStyle="None" which you need if you are doing custom chrome.

Categories