mvvm - 使用 Caliburn 在 Windows 应用商店中绑定(bind)组合框

标签 mvvm windows-8 windows-store-apps winrt-xaml caliburn.micro

我正在尝试使用 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 , herehere .

基本上,只需将此行添加到 Configure方法:

container.PerRequest<yyyViewModel>();

关于mvvm - 使用 Caliburn 在 Windows 应用商店中绑定(bind)组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15483431/

相关文章:

c# - 有关使用 WCF 服务的 MVVM 模式的一般问题

windows-8 - 在保持触摸选择项目的能力的同时启用鼠标滚动

c# - 关闭 MessageDialog 后聚焦 WebView

xaml - HeaderedItemsControl 的 Metro 等效项

c# - Windows 应用商店应用程序 : how to programmatically launch bluetooth settings app

android - 未知属性 onItemSelected/onCheckedChanged

c# - WPF ContentControl 无法从 ViewModel 解析正确的 View (Catel)

c# - MVVM 动态添加字段到 View 中

windows-8 - Windows 8 准备站点以进行固定

javascript - Windows 应用商店应用程序 - 从辅助磁贴启动时执行单个任务