Reputation: 4081
I have an app that has two secondary windows. I have buttons that let you switch between windows, which works fine:
ApplicationViewSwitcher.SwitchAsync(_viewToSwitchToId);
When the user launches our app via the jumplist (under the recent heading when you right click on the app icon in the taskbar), I would like to be able to choose which secondary window to focus on.
I use the same code as above, but it does not work (the same secondary window is automatically chosen regardless of what _viewToSwitchToId
I provide).
I'm guessing there's some difference between calling the SwitchAsync()
from when my app already has focus (from my button) and when it does not have focus (jumplist).
Any ideas?
Edit
Git repository with repro of SwitchAsync()
issue.
Upvotes: 1
Views: 466
Reputation: 10627
I would like to be able to choose which secondary window to focus on
I added the SwitchAsync()
method to OnLaunched
for a testing, and when launch the app from the jump list, the application view will switch to the assigned view correctly. For example:
protected override async void OnLaunched(LaunchActivatedEventArgs e)
{
...
CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
Frame frame = new Frame();
Window.Current.Content = frame;
Window.Current.Activate();
newViewId = ApplicationView.GetForCurrentView().Id;
});
await ApplicationViewSwitcher.SwitchAsync(newViewId);
//bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
}
If you still have issues please provide a minimal reproduced project for a testing on our side.
Updated:
SwitchAsync(Int32, Int32)
method can work well for your scenario. For example:
// Create 2 secondary views
CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
Frame frame = new Frame();
frame.Navigate(typeof(page1));
Window.Current.Content = frame;
Window.Current.Activate();
ApplicationView appView = ApplicationView.GetForCurrentView();
newViewId = appView.Id;
appView.Title = newViewId.ToString();
_viewIds.Add(newViewId);
});
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
CoreApplicationView newView2 = CoreApplication.CreateNewView();
int newViewId2 = 0;
await newView2.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
Frame frame = new Frame();
frame.Navigate(typeof(page2));
Window.Current.Content = frame;
Window.Current.Activate();
ApplicationView appView = ApplicationView.GetForCurrentView();
newViewId2 = appView.Id;
appView.Title = newViewId2.ToString();
_viewIds.Add(newViewId2);
});
bool viewShown2 = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId2);
// Switch to first secondary view, BUT focuses on last secondary view :/
Debug.WriteLine("Switching to secondary view with id: " + _viewIds[0]);
// bool viewShowntoone = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(_viewIds[0]);
await ApplicationViewSwitcher.SwitchAsync(_viewIds[0], _viewIds[1]);
Upvotes: 1