I have created a custom UserControl. It is basically a combobox that allow a multiple selection (each combobox item is a checkbox). Everything works fine except for the Selected items property
public static readonly DependencyProperty SelectedItemsProperty =
DependencyProperty.Register("SelectedItems", typeof(ObservableCollection<string>), typeof(MultiSelectionComboBox), new FrameworkPropertyMetadata(null,
new PropertyChangedCallback(MultiSelectionComboBox.OnSelectedItemsChanged)));
public ObservableCollection<string> SelectedItems
{
get { return (ObservableCollection<string>)GetValue(SelectedItemsProperty); }
set
{
SetValue(SelectedItemsProperty, value);
}
}
private static void OnSelectedItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MultiSelectionComboBox control = (MultiSelectionComboBox)d;
control.SetText();
}
On this side the things seems to work, meaning that the the SelectedItems change and the callback is triggered when i select a new item. The problem rise when i use this custom usercontrol.
This is how i have defined it:
<views:MultiSelectionComboBox SelectedItems="{Binding Path=IpAddressSelection, UpdateSourceTrigger=PropertyChanged}" Background="White" BorderThickness="1" ItemsSource="{Binding Path=Address}" BorderBrush="LightGray" Grid.Row="0" Grid.Column="1" Width="200" Margin="70 10 0 0" DefaultText="Indirizzo IP..." />
This is the binding of the SelectedItems property:
public ObservableCollection<string> IpAddressSelection
{
get { return ipAddressSelection; }
set
{
SetField(ref ipAddressSelection, value, "IpAddressSelection");
}
}
private ObservableCollection<string> ipAddressSelection = new ObservableCollection<string>();
SetField is a function that implement the INotifyPropertyChanged interface. My problem is that when i select an item, IpAddressSelection does not see any change (i.e. i can't get inside the "set" of IpAddressSelection). Do you know what i'm doing wrong here?