我正在尝试在我的ToggleButton
. 这是我的ToggleButton
:
<ToggleButton Template="{StaticResource OnTemplate}" IsChecked="True" >
<ToggleButton.Style>
<Style TargetType="ToggleButton">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsChecked}" Value="True">
<Setter Property="Template" Value="{StaticResource OnTemplate}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsChecked}" Value="False">
<Setter Property="Template" Value="{StaticResource OffTemplate}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
</ToggleButton>
这是两个模板:
<ControlTemplate x:Key="OnTemplate">
<Grid>
<Image Source="ToggleOn.png" />
<TextBlock>On</TextBlock>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="OffTemplate">
<Grid>
<Image Source="ToggleOff.png" />
<TextBlock>Off</TextBlock>
</Grid>
</ControlTemplate>
这似乎行不通。我究竟做错了什么?