I've got a custom control CheckableItemsControl
that I've thrown together, it's lookless, has no dependency properties of its own and just derives from ItemsControl
.
Following Rachel's answer in this question: How can I overwrite my ListBox's ItemTemplate and still keep the DisplayMemberPath? I've managed to come up with the following style in Generic.xaml:
<Style x:Key="{x:Type controls:CheckableItemsControl}" TargetType="{x:Type controls:CheckableItemsControl}"
BasedOn="{StaticResource {x:Type ItemsControl}}">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<CheckBox IsChecked="{Binding IsChecked}" Content="{TemplateBinding ContentPresenter.Content}"
ContentTemplateSelector="{TemplateBinding ContentPresenter.ContentTemplateSelector}"
Margin="5" />
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:CheckableItemsControl}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom"
Grid.Row="0"
Margin="0,0,0,3">
<Button x:Name="PART_SelectAllButton" Content="Select All" Width="60" Margin="5,0,5,0" />
<Button x:Name="PART_InvertButton" Content="Invert" Width="60" Margin="5,0,5,0" />
</StackPanel>
<Border Grid.Row="1" BorderBrush="{x:Static SystemColors.ActiveBorderBrush}" BorderThickness="1">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<ItemsPresenter />
</ScrollViewer>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And using it is like this:
<controls:CheckableItemsControl ItemsSource="{Binding Reports}" DisplayMemberPath="ReportName" />
Now, this works just fine at design time, the designer correctly renders the items with their ReportName
being displayed as text.
At runtime however, it just renders the type name like you'd expect with no content template.
I can't work out why this would fail at runtime.