I have a dependency property(List of string) in a user control in my dot net assembly as below
public partial class ItemSelectionUserControl : UserControl
{
public List<string> AvailableItems
{
get { return (List<string>)this.GetValue(AvailableItemsProperty); }
set { this.SetValue(AvailableItemsProperty, value); }
}
public static readonly DependencyProperty AvailableItemsProperty = DependencyProperty.Register(
"AvailableItems", typeof(List<string>), typeof(ItemSelectionUserControl), new FrameworkPropertyMetadata{BindsTwoWayByDefault =true});
public ItemSelectionUserControl()
{
InitializeComponent();
}
}
I am trying to use this usercontrol in another usercontrol in a different assembly as below
<UserControl
xmlns:ctrl="clr-namespace:HH.Windows.UserControls;assembly=HH.Windows.UserControls"
/>
// .....
<Grid>
<ctrl:ItemSelectionUserControl Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="3" AvailableItems="{Binding Path=CheckList}"/>
</Grid>
I can see the get accessor of CheckList is getting called, but it is not setting the dependency property “AvailableItems”. The breakpoint in the set of “AvailableItems” is never getting called. What am I doing wrong?
As far as I’m aware, WPF may not call the setter of your property directly if it exposes a
DependencyProperty. Instead it can set theDependencyPropertydirectly. For more information, see Dependency Properties Overview on MSDN. In particular this section:To test whether this is occurring in your example (plus get a notification where you can operate on the set value), you can try adding a Callback in the
FrameworkPropertyMetadatae.g.