c# - WP7 上 ListPicker 的 caliburn.micro 绑定(bind)约定

标签 c# windows-phone-7 silverlight-toolkit caliburn.micro listpicker

我正在为一个新项目尝试 caliburn.micro 框架,但我坚持绑定(bind)一个 ListPicker(工具包中的那个)。当我将控件更改为简单的 DropDown 时,一切都按预期进行。 我假设 DropDown 工作正常,因为实现了默认约定 here :

AddElementConvention<Selector>(Selector.ItemsSourceProperty, "SelectedItem", "SelectionChanged")
    .ApplyBinding = (viewModelType, path, property, element, convention) => {
        if (!SetBinding(viewModelType, path, property, element, convention))
            return false;

        ConfigureSelectedItem(element, Selector.SelectedItemProperty,viewModelType, path);
        ApplyItemTemplate((ItemsControl)element, property);

        return true;
    };

ListPicker 没有实现 Selector,所以我尝试在我的 Bootstrap 中添加自定义约定:

static void AddCustomConventions() {
    AddElementConvention<ListPicker>(ListPicker.ItemsSourceProperty, "SelectedItem", "SelectionChanged")
        .ApplyBinding = (viewModelType, path, property, element, convention) => {
            ConventionManager.ConfigureSelectedItem(element, ListPicker.SelectedItemProperty,viewModelType, path);
            return true;
        };
}

不幸的是,那行不通。你能帮忙吗?

最佳答案

我用这个约定解决了我的问题。

ConventionManager.AddElementConvention<ListPicker>(ListPicker.ItemsSourceProperty, "SelectedItem", "SelectionChanged")
    .ApplyBinding = (viewModelType, path, property, element, convention) =>
    {
        if (ConventionManager.GetElementConvention(typeof(ItemsControl)).ApplyBinding(viewModelType, path, property, element, convention))
        {
            ConventionManager.ConfigureSelectedItem(element, ListPicker.SelectedItemProperty, viewModelType, path);
            return true;
        }
        return false;
    };

此外,还有一个问题。我的 SelectedItem 属性返回 null 但我的 Items 属性不包含 null 值。我得到一个异常,所选项目无效,因为它不在列表中。

关于c# - WP7 上 ListPicker 的 caliburn.micro 绑定(bind)约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6729704/

相关文章:

c# - 如何从 Xamarin 中的 Assets 文件夹读取 Json/文本文件

silverlight - Windows Phone 7 应用程序中的 Paypal

windows - VS2010 SP1 安装。 “The feature you are trying to use is on a network resource that is unavailable”

silverlight - Silverlight 4 工具包中的 WrapPanel

c# - 合并两个 SyndicationFeed

c# - 如何使用 JSONPath (或任何其他选项)来查询未命名的 JSON 数组?

c# - 是否应为同一实体创建多个数据契约(Contract)

windows-phone-7 - 如何在 Windows Phone 7 上本地化 ToggleSwitch(本地化 Silverlight Toolkit)?

windows-phone-7 - 点击上下文菜单,而不是使用按钮控件点击并按住

c# - 工具包图表旋转标签 X 轴