Note: Source of this knowledge was from some blog....
SelectedItems on ListBox is a readonly property. I need to bind a list to multiple selections on ListBox and also list needs to support two way binding.
Took a ListBoxExtension class with two attached properties.
a) One attached property is used to bind to the selectionItems observablecollection in the viewmodel. The property change callback initializes the other dependency property with an instance of a class that keeps track of list changes.
public static readonly DependencyProperty SelectionItemsProperty = DependencyProperty.RegisterAttached("SelectionItems",
typeof(IList), typeof(ListBoxExtension), new PropertyMetadata(null, new PropertyChangedCallback(OnSelectedItemsChanged)));
b) Other dependency property is used for ListBoxExtensionHelper class implementing IWeakEventListener, that keeps track of change events between our viewModel SelectionItems list and listboxes selectedItems list. ReceiveWeakEvent was interesting here....
private static readonly DependencyProperty ExtensionHelperProperty = DependencyProperty.RegisterAttached(
"ExtensionHelper", typeof(ListBoxExtensionHelper), typeof(ListBoxExtension), new PropertyMetadata(null));
SelectedItems on ListBox is a readonly property. I need to bind a list to multiple selections on ListBox and also list needs to support two way binding.
Took a ListBoxExtension class with two attached properties.
a) One attached property is used to bind to the selectionItems observablecollection in the viewmodel. The property change callback initializes the other dependency property with an instance of a class that keeps track of list changes.
public static readonly DependencyProperty SelectionItemsProperty = DependencyProperty.RegisterAttached("SelectionItems",
typeof(IList), typeof(ListBoxExtension), new PropertyMetadata(null, new PropertyChangedCallback(OnSelectedItemsChanged)));
b) Other dependency property is used for ListBoxExtensionHelper class implementing IWeakEventListener, that keeps track of change events between our viewModel SelectionItems list and listboxes selectedItems list. ReceiveWeakEvent was interesting here....
private static readonly DependencyProperty ExtensionHelperProperty = DependencyProperty.RegisterAttached(
"ExtensionHelper", typeof(ListBoxExtensionHelper), typeof(ListBoxExtension), new PropertyMetadata(null));
No comments:
Post a Comment