I have a problem with the following scenario (shortening the code for short). Basically, the Setter of my User Control property is not called when the dependency property is set, and I need to get around this.
I have the following code in my View.xaml
<Filter:Filter x:Name="ProductFilter" PrimaryItemSource="{Binding CarrierProducts}" />
In View.xaml.cs
public ProductPricing() { InitializeComponent(); ViewModel.Filter.ProductPricing vm = new ViewModel.Filter.ProductPricing(); this.DataContext = vm; }
In my ViewModel, I set the property
public ObservableCollection<Model.FilterItem> _carrierProducts; public ObservableCollection<Model.FilterItem> CarrierProducts { get { return _carrierProducts; } set { if (_carrierProducts != value) { _carrierProducts = value; RaisePropertyChanged("CarrierProducts"); } } }
Finally, the user filter control is defined as follows.
public static readonly DependencyProperty PrimaryItemSourceProperty = DependencyProperty.Register("PrimaryItemSource", typeof(ObservableCollection<Model.FilterItem>), typeof(Filter), new PropertyMetadata(null)); public ObservableCollection<Model.FilterItem> PrimaryItemSource { get { return (ObservableCollection<Model.FilterItem>)GetValue(PrimaryItemSourceProperty); } set { SetValue(PrimaryItemSourceProperty, value); ComboBox combo = _filters.ElementAt(0); FilterSourceChange(combo, value); } }
For some reason, the PrimaryItemSource property is set, but Setter is not called. Should I add a PropertyChange event to the PropertyMetadata object to handle this, as this seems like a lot of code for something simple.
source share