I know this wasn't right when I wrote it and I've been able to glean most of the answer for another answer, but just can't grasp the final bit. The binding does pass from the UI to the DependencyProperty (and the other way when the control is created).
My Template (need to move the IsChecked binding to the instance):
<ControlTemplate x:Key="MyHeaderedContentTemplate" TargetType="HeaderedContentControl">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<ContentControl>
<StackPanel Orientation="Horizontal">
<CheckBox Margin="2,2,20,2"
Content="All/None"
IsChecked="{Binding Path=AllFeatureTypesChecked, Mode=TwoWay}" />
<TextBlock Text="{TemplateBinding Header}" Margin="2"/>
</StackPanel>
</ContentControl>
<ContentControl Grid.Row="1" Content="{TemplateBinding Content}" />
</Grid>
The Instance:
<HeaderedContentControl Grid.Row="0" Grid.Column="2" Grid.RowSpan="2" Grid.ColumnSpan="2" Margin="4"
Template="{StaticResource ResourceKey=MyHeaderedContentTemplate}"
Header="Feature Details by Type">
<HeaderedContentControl.Resources>
</HeaderedContentControl.Resources>
<ListBox ItemTemplate="{StaticResource SelectableLinkNode}"
ItemsSource="{Binding Features}"/>
</HeaderedContentControl>
And the Setter (of course, there's a Boolean AllFeatureTypesChecked DependencyProperty):
/// <summary>
/// Needs to be set on Startup and on ItemIsCheckedChanged Event from the Features List
/// </summary>
private void SetAllSelectedState()
{
bool allSelected = (Features.Count > 0);
foreach (var CheckableItem in Features) {
if (CheckableItem.IsChecked == false) {
allSelected = false;
break;
}
}
SetCurrentValue(AllFeatureTypesCheckProperty, allSelected);
}
For reference, here's the DP
public static readonly DependencyProperty AllFeatureTypesCheckProperty =
DependencyProperty.Register("AllFeatureTypesCheck", typeof(Boolean), typeof(ReportSources),
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAllFeatureTypesCheckedChanged));
This is really fun stuff and I couldn't do it without the awesome folks here on SO! Thanks!
UPDATE: OK, Now I've got this (brainstorm):
<ControlTemplate x:Key="MyHeaderedContentTemplate" TargetType="HeaderedContentControl">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<ContentControl>
<StackPanel Orientation="Horizontal">
<ContentPresenter Content="{DynamicResource ResourceKey=CheckControl}" Margin="2,2,20,2"/>
<TextBlock Text="{TemplateBinding Header}" Margin="2"/>
</StackPanel>
</ContentControl>
<ContentControl Grid.Row="1" Content="{TemplateBinding Content}" />
</Grid>
</ControlTemplate>
instantiated like so:
<HeaderedContentControl Grid.Row="0" Grid.Column="2" Grid.RowSpan="2" Grid.ColumnSpan="2" Margin="4"
Template="{StaticResource ResourceKey=MyHeaderedContentTemplate}"
Header="Feature Details by Type"
>
<HeaderedContentControl.Resources>
<CheckBox x:Key="CheckControl"
Content="All/None"
IsThreeState="True"
IsChecked="{Binding Path=AllFeatureTypesChecked, Mode=TwoWay}"
/>
</HeaderedContentControl.Resources>
<ListBox ItemTemplate="{StaticResource SelectableLinkNode}"
ItemsSource="{Binding Features}"/>
</HeaderedContentControl>
but still can't get the value set on the DP to show on the UI after the control has been created.
...sure could use a little help here, Thanks.