Reputation: 1241
public class MainViewModel MyViewModel : INotifyPropertyChanged
{
Window window { get; set; }
public MyViewModel()
{
window = Window.Current;
}
async void MyWebSocketService_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "ActivateWindow"
ActivateWindow();
break;
}
}
void ActivateWindow()
{
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
window.Activate();
window.CoreWindow.Activate();
});
}
}
I'm trying to get a hidden or minimized UWP app to regain focus in the OS upon a WebSocket notification. This is the code I tried. It fires but nothing happens. Is there a way to achieve what I'm trying to do?
Upvotes: 3
Views: 717
Reputation: 13850
A UWP app cannot resume itself from minimized state because its execution state is suspended (and therefore can't run any code). The resume needs to be triggered externally, either by the user or by another running app, which can activate the suspended UWP app via any of the supported app activation APIs, for example doing a launch via protocol - as you have already figured out.
Upvotes: 5