How do I bind to a DependencyProperty instance that is held in a CLR property, from XAML?
I'm trying to generate a 'settings' list (user can modify app. settings via a list of checkboxes).
I would like the list to be dynamically created from the dependency properties in a certain class (MyOptions). This I've achieved, I bind the ListBox to this list (which is a list of DependencyProperty objs)
public IEnumerable<OptionProperty> AvailableOptions
{
get
{
return from property in GetAttachedProperties(MyOptions)
where property.GetMetadata(MyOptions) is OptionPropertyMetaData
select new OptionProperty { OptionName = property.Name, OptionType = property.PropertyType, OptionDependencyProperty = property };
}
}
What I need to do is bind the check box in the DataTemplate (for the ListBox) to the DependencyProperty items in the list.
So of course this isn't going to work
<DataTemplate DataType="{x:Type local:OptionProperty}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="30"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Path=OptionName}" />
<CheckBox Grid.Column="1" HorizontalAlignment="Right" IsChecked="{Binding Path=OptionDependencyProperty}"></CheckBox>
</Grid>
</DataTemplate>
because it's just binding to the property of OptionProperty called OptionDependencyProperty, instead of the DependencyProperty that is referenced in OptionDependencyProperty.
So how do I bind to a DependencyProperty instance that is held in a CLR property (OptionDependencyProperty), from XAML?
I think my brain-stack is full and can't deal with the abstraction anymore :(
Thanks!
OptionProperty
declaration will be useful.