我正在尝试使用VS2013 RC在Caliburn.Micro WinRT 8.1应用程序中打开设置视图,但是在打开并显示以下消息时,我始终收到未处理的异常:
值不能为空。参数名称:无法解析应用清单中的VisualElement。
我可以通过以下步骤重现这些问题:
代码如下:
public sealed partial class App
{
private WinRTContainer _container;
public App()
{
InitializeComponent();
}
protected override void Configure()
{
_container = new WinRTContainer();
_container.RegisterWinRTServices();
_container.PerRequest<MainViewModel>();
_container.PerRequest<SettingsViewModel>();
ISettingsService settings = _container.RegisterSettingsService();
settings.RegisterCommand<SettingsViewModel>("Test settings");
}
protected override object GetInstance(Type service, string key)
{
var instance = _container.GetInstance(service, key);
if (instance != null) return instance;
throw new Exception("Could not locate any instances.");
}
protected override IEnumerable<object> GetAllInstances(Type service)
{
return _container.GetAllInstances(service);
}
protected override void BuildUp(object instance)
{
_container.BuildUp(instance);
}
protected override void PrepareViewFirst(Frame rootFrame)
{
_container.RegisterNavigationService(rootFrame);
}
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
DisplayRootView<MainView>();
}
}
启动应用程序时,可以看到主视图;然后打开超级按钮栏并单击设置,然后找到通往我的应用设置的标签;当我单击它时,我得到上面引用的异常。有什么提示吗?
您可以在此处找到完整的repro解决方案:http : //sdrv.ms/18GIMvB。
看来新的CM版本(alpha 2)解决了这个问题,所以我在这里添加了更多信息来帮助像我这样的其他新手。这是我现在正在做的事情:
在应用程序中,Configure
我有一些引导代码,例如:
...
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse("Resources");
ISettingsService settings = _container.RegisterSettingsService();
settings.RegisterFlyoutCommand<ContentSettingsViewModel>(loader.GetString("SettingsContent"));
的ContentSettingsViewModel
是,用于过滤一些内容的视图模型。从资源获取的字符串是将出现在设置弹出窗口中的标签(请确保该字符串有一个条目,因为传递空字符串或null字符串会触发异常)。这个VM是从CM衍生Screen
因为我重写OnActivate
,并OnDeactivate
加载和保存设置,当用户打开或驳回设置页面。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句