繁体   English   中英

WP7 上 ListPicker 的 caliburn.micro 绑定约定

[英]caliburn.micro binding convention for ListPicker on WP7

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

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 没有实现选择器,所以我尝试在我的引导程序中添加一个自定义约定:

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 值。 我有一个例外,即所选项目无效,因为它不在列表中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM