Binding SelectedItems crash
Hello,
maybe I'm doing something very silly, but if I try to bind the SelectedItems property of the control I get exceptions as the dependencyproperty seems to be null, even if I initialised it.
Is there something big I'm missing?
Thanks, Claudio
I've looked at the code and I think the problem lies with the initialization of the SelectedItems property.
It is initialized at the following lines in the constuctor: https://github.com/ygoe/MultiSelectTreeView/blob/8dadce5dfa1fce0216c906921f0edf9551dbc457/MultiSelectTreeView/Controls/MultiSelectTreeView.cs#L89-L91
whereas it should be initialized in the metadata of the DependencyProperty with something like the following:
public static DependencyProperty SelectedItemsProperty = DependencyProperty.Register(
"SelectedItems",
typeof(IList),
typeof(MultiSelectTreeView),
new FrameworkPropertyMetadata(
new ObservableCollection<object>(),
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
OnSelectedItemsPropertyChanged)
);
I'm happy to post a PR if this solution works for you.
I think I've never done that. My approach was to bind each item's IsSelected property (this is prone to missed notifications while items are virtualised away) or do the selection stuff in the view code (.xaml.cs) instead. I'm not using this code anymore and I can't offer much support for it now.