我希望能夠選擇哪些輔助窗口集中
我加入了SwitchAsync()
方法OnLaunched
進行測試,當發射從跳轉列表中的應用程序,該應用程序視圖將正確切換到指定的視圖。例如:
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);
}
如果您仍有問題,請提供一個最小複製項目,以便我們進行測試。
更新時間: SwitchAsync(Int32, Int32)
方法可以爲您的方案很好地工作。例如:
// 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]);
感謝您的快速響應Sunteen!你有兩個二級窗口測試嗎?只要只有一個輔助窗口,它就可以正常工作,但只要有更多'SwitchAsync(viewId)'忽略'viewId'參數。我已經添加了一個[git repo](https://github.com/fman028/FocusOnSecondaryWindowIssue)來突出顯示這個問題。 – Felix
你有機會嘗試git回購嗎? – Felix
@Felix。我測試過了。在你的場景中,你可能需要通過'SwitchAsync(Int32,Int32)'方法從另一個視圖指定另一個視圖。有關代碼詳情,請參閱更新的回覆。 –