Hi,
Using an MVVM approach to WPF, I have a view model class called SubButton. It is styled as follows:
<!-- SubNavButton Appearance -->
<ControlTemplate x:Key="SubNavButton" TargetType="{x:Type RadioButton}">
<Grid Margin="5,5">
<Rectangle x:Name="rectBackground" Fill="DimGray" Stroke="#FF000000" Width="150" Height="40" StrokeThickness="1"/>
<TextBlock x:Name="txtContent" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Arial" FontSize="16">
<ContentPresenter />
</TextBlock>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Fill" TargetName="rectBackground" Value="Red"/>
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Fill" TargetName="rectBackground" Value="Pink"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!-- SubButton data template -->
<DataTemplate DataType="{x:Type VM:SubButton}">
<RadioButton
Template="{StaticResource SubNavButton}"
Content="{Binding TempText}"
Command="{Binding SubFrameChanger.Command}"
CommandParameter="{Binding Key}"
GroupName="{Binding MenuGroup}"
V:CreateCommandBinding.Command="{Binding SubFrameChanger}" />
<DataTemplate.Triggers>
<!-- This trigger doesn't work -->
<DataTrigger Binding="{Binding Path=Selected}" Value="True">
<Setter TargetName="rectBackground" Property="Fill" Value="Green"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
The DataTrigger doesn't work. "Selected" is a regular .Net property on the SubButton class. I am getting a compilation error because the compiler can't figure out where the "rectBackground" target comes from. It is part of the ControlTemplate, I'm not sure how to tell it that? Something about the data context?