Caliburn.micro binding agreement for ListPicker on WP7

I'm trying to create the caliburn.micro platform for a new project, but I'm stuck in a ListPicker binding (the one from the toolbox). When I change the control to a simple DropDown, everything works as expected. I assume DropDown is working properly, due to the default convention 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 does not implement a selector, so I tried to add a user agreement to my loader:

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

Unfortunately this does not work. You can help?

+4
source share
1 answer

I solved the problem with this agreement.

 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; }; 

Additionally, another problem arose. My SelectedItem Property returned null, but the Items property did not contain a null value. I got an exception that the selected item is not valid because it is not in the list.

+8
source

All Articles