我正在尝试为TipCalc示例创建一个UWP应用程序的版本:https://github.com/MvvmCross/MvvmCross-Samples/tree/master/TipCalc
在示例中已经有了一个UWP版本,它工作得很好。然而,我正在尝试使用Template10 (https://github.com/Windows-XAML/Template10),并且很难让这两个库一起工作。
MvvmCross希望我修改OnLaunched方法,该方法具有对根框架的引用。但是,模板10抽象了这个方法,公开了没有引用的OnStartAsync .
CreateRootFrame的模板10中有一个覆盖,这似乎是初始化mvvmcross应用程序的正确位置,但这似乎不像我所期望的那样工作.
虽然启动的应用程序确实导航到适当的页面,并且似乎也初始化了视图模型(关联的VM中的Start方法上的一个断点确实被击中了),但是页面本身是空的。
比较这两个应用程序的视觉树可以发现,虽然示例中现有的UWP应用程序有一个框架:

我的Template10应用程序正在加载一个Modal对话框:

我分叉了原始示例项目,并添加了模板10版本,如果您想自己尝试的话:https://github.com/selaromdotnet/MvvmCross-Samples
还有其他人能够将MvvmCross与模板10集成吗?你知不知道我做错了什么,以及在一起使用这两个库的最佳实践有什么建议?
发布于 2016-05-19 05:20:42
嗯,根据当前的文档,ModalDialog是Template10的预期行为:https://github.com/Windows-XAML/Template10/wiki/Docs-|-Bootstrapper
我对OnInitializeAsync,还不太熟悉,无法解释为什么会出现这种情况,但它也说您可以通过重写Template10来改变这种情况,恢复原始框架的方式与常规的UWP项目一样:
public override async Task OnInitializeAsync(IActivatedEventArgs args)
{
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
var setup = new Setup(rootFrame);
setup.Initialize();
}
await Task.CompletedTask;
}这招成功了!我确信我还有一段路要走(我相信Template10有它自己的恢复状态的方法,所以我可能不应该在这里这样做)。
但这至少让我找到了一款实用的应用程序。如果你知道我在这里做错了什么,或者我应该做什么,你的评论将会非常感谢,谢谢!
https://stackoverflow.com/questions/37314059
复制相似问题