我正在尝试使用 Caliburn 和以下代码绑定(bind)组合框:
yyyView.xaml
<ComboBox x:Name="Filters"></ComboBox>
yyyViewModel.xaml
private string selectedFilter;
public BindableCollection<string> Filters
{
get
{
return new BindableCollection<string>(
new string[]{ "All", "Last Month", "Last Week", "Yesterday" });
}
}
public string SelectedFilter
{
get { return selectedFilter; }
set
{
selectedFilter = value;
NotifyOfPropertyChange(() => SelectedFilter);
}
}
使用此代码,我得到一个 ArgumentNullException 在 应用程序.xaml.cs 在 获取实例 方法。
我是 MVVM、Caliburn 和 XAML 的新手,但我在某处读过一些行为(我相信 Blend Behaviors )在 WinRT 开发中下降。
那是问题吗?我该如何解决这个问题?
谢谢
编辑:
应用程序.xaml.cs
protected override void Configure()
{
LogManager.GetLog = type => new DebugLogger(type);
container = new WinRTContainer();
container.RegisterWinRTServices();
container.PerRequest<aaaViewModel>();
container.PerRequest<xxxViewModel>();
container.PerRequest<yyyViewModel>();
container.PerRequest<zzzViewModel>();
}
应用程序.xaml
<caliburn:CaliburnApplication
x:Class="yyyStoreApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:yyyApp"
xmlns:caliburn="using:Caliburn.Micro"
xmlns:converters="using:yyyApp.Converters"
RequestedTheme="Light">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/CustomStyles.xaml" />
<ResourceDictionary Source="Resources/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
<converters:ImageFilePathConverter x:Key="ImageFilePath"/>
</ResourceDictionary>
</Application.Resources>
</caliburn:CaliburnApplication>
最佳答案
您可能尚未在 Configure
中注册 View 模型App
中的方法重载执行。请查看// TODO
参与App
WinRT documentation 中的代码.
这显然是预期的行为,但引起了一些困惑,如 CodePlex 上的讨论论坛和问题跟踪器所示,请参阅 here , here和 here .
基本上,只需将此行添加到 Configure
方法:
container.PerRequest<yyyViewModel>();
关于mvvm - 使用 Caliburn 在 Windows 应用商店中绑定(bind)组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15483431/