Hi,
I am having a user control, in which the user can select multiple values, and the selected values got pushed to the associated VM Prop.
I am sure that, I have not set binding to the DP programmatic. But while assigning the value to the CLR Property (back up for the DP), it is not firing the associated VM prop's setter.
Hereby, I have shared the code.
public ObservableCollection<Sector> SelectedItems { get { return (ObservableCollection<Sector>)GetValue(SelectedItemsProperty); } set { SetValue(SelectedItemsProperty, value); } } public static readonly DependencyProperty SelectedItemsProperty = DependencyProperty.Register("SelectedItems", typeof(ObservableCollection<Sector>), typeof(MultiSelectComboBox),new PropertyMetadata(null)); private void CheckBox_Checked(object sender, RoutedEventArgs e) { PushSelectedItems(); } public void PushSelectedItems() { //***Here I am assigning the values*** SelectedItems = new ObservableCollection<Sector>(DataSource.Where(x => x.IsSelected == true)); }
The method "CheckBox_Checked", is associated with the checkbox checked event.
I will use this User Control, in a another control as below:-
Case 1:-
<CustomUC:MultiSelectComboBox DataSource="{Binding AreaSectors}"SelectedItems="{Binding SelectedSector}"/>
Where "SelectedSector" is a VM property.
However, this code works, when I change the Binding Mode to TwoWay in the "SelectedItems" as follows:-
Case 2:-
<CustomUC:MultiSelectComboBox DataSource="{Binding AreaSectors}"SelectedItems="{Binding SelectedSector,Mode=TwoWay}"/>
PS:-
My question is, I am just pumping data, from View to VM through the DP prop.
Why I am not getting the setter to be called upon assigning the value to the DP backed up
CLR prop in "case 1". If I want to set any Binding Mode, then why I have to set that mode.
But this works fine, when I have mentioned to be Mode=TwoWay.
May I kindly know, where I am getting wrong in making the DP.
Thanks in advance.
NANDAKUMAR.T