WP7上ListPicker的caliburn.micro绑定约定

Mic*_*elS 4 c# silverlight-toolkit windows-phone-7 caliburn.micro listpicker

我正在为一个新项目尝试使用caliburn.micro框架,但我坚持使用绑定ListPicker(工具包中的那个).当我将控件更改为简单的DropDown时,一切都按预期工作.我假设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;
    };
Run Code Online (Sandbox Code Playgroud)

ListPicker没有实现Selector,所以我试图在我的引导程序中添加一个自定义约定:

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

不幸的是,这不起作用.你能帮我吗?

Mic*_*elS 8

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

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;
    };
Run Code Online (Sandbox Code Playgroud)

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