Prism Library UWP显示应用程序的多个视图
我正在尝试棱镜库UWP 我得到了Prism Library UWP显示应用程序的多个视图,uwp,prism,prism-4,Uwp,Prism,Prism 4,我正在尝试棱镜库UWP 我得到了frame.Navigate(typeof(屏幕截图))的System.NullReferenceException如下所示: async void ExecuteNewWindow() { CoreApplicationView newView = CoreApplication.CreateNewView(); int newViewId = 0; awai
frame.Navigate(typeof(屏幕截图))的System.NullReferenceException
代码>如下所示:
async void ExecuteNewWindow()
{
CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
Frame frame = new Frame();
frame.Navigate(typeof(ScreenCapture));
Window.Current.Content = frame;
// You have to activate the window in order to show it later.
Window.Current.Activate();
newViewId = ApplicationView.GetForCurrentView().Id;
});
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
}
如何在Prism库中为uwp实现多视图。您的项目是Xamarin.Forms,但是frame.Navigate(typeof(screenscapture))的参数代码>是uwp页面类型。我检查了你的代码,screenscapture
是表单ContentPage
。根据您的需求,您可以使用调用executenewindow
并将executenewindow
放置在UWP项目中
接口
public interface INewPageService
{
void CreateNewPage();
}
DependencyService.Get<INewPageService>(DependencyFetchTarget.NewInstance).CreateNewPage();
实施
[assembly: Dependency(typeof(INewPageService))]
namespace BlankApp1.UWP
{
public class INewPageServiceImplement : INewPageService
{
public async void CreateNewPage()
{
CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
Frame frame = new Frame();
frame.Navigate(typeof(NewPage)); // uwp page
Window.Current.Content = frame;
// You have to activate the window in order to show it later.
Window.Current.Activate();
newViewId = ApplicationView.GetForCurrentView().Id;
});
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
}
}
}
用法
public interface INewPageService
{
void CreateNewPage();
}
DependencyService.Get<INewPageService>(DependencyFetchTarget.NewInstance).CreateNewPage();
DependencyService.Get(DependencyFetchTarget.NewInstance).CreateNewPage();
请不要忘记在uwp app.xaml.cs文件中注册它
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
Xamarin.Forms.Forms.Init(e);
DependencyService.Register<INewPageService, INewPageServiceImplement>();
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if(rootFrame==null)
{
//创建一个框架作为导航上下文并导航到第一页
rootFrame=新框架();
rootFrame.NavigationFailed+=OnNavigationFailed;
Xamarin.Forms.Forms.Init(e);
DependencyService.Register();
如果(例如,PreviousExecutionState==ApplicationExecutionState.Terminated)
{
//TODO:从先前挂起的应用程序加载状态
}
//将框架放置在当前窗口中
Window.Current.Content=rootFrame;
}
这很奇怪,我运行了上面的代码,但我无法再次重现您的问题。你能分享一个可以重现这个问题的代码示例吗?应用程序的目标和min版本是1903 1809,操作系统版本是1909。@NicoZhu MSFT对于这个问题,我使用的是Prism库框架。您是否使用prism进行测试?是的,我使用Template Studio创建了示例,并添加了prism库,效果很好。@NicoZhu MSFT请检查此项,谢谢提供详细的解决方案。关于scrren捕获的另一个问题是什么?你能重现屏幕捕获问题吗?我检查了,但我无法重现你的问题,请检查你的公司政策,如果锁定outlook捕获功能。目前,我测试我自己的电脑,它是1903,仍然有这个问题。请检查这个,它在我这边运行良好。你能试着用计算机is 1906或更低版本而不是1909进行测试吗?