0
我正在尝试构建RadioButton
的模板,如选择时发生更改。wpf使用触发器设计RadioButton
<RadioButton GroupName="NewTabButons" Content="{Binding TabTitle}"
Background="{StaticResource CanvasBackgroundColour}"
Command=... CommandParameter=...>
<RadioButton.BorderBrush>...</RadioButton.BorderBrush>
<RadioButton.Template>
<ControlTemplate TargetType="RadioButton">
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true">
<Setter Property="Control.Background" Value="AliceBlue" />
<Setter Property="Control.Foreground" Value="{StaticResource TabTextColourActive}" />
</Trigger>
</ControlTemplate.Triggers>
<Border Height=... Width=... Padding=... VerticalAlignment=...
Background="{TemplateBinding Background}"
BorderThickness="0 0 0 10"
BorderBrush="{TemplateBinding BorderBrush}">
<Border.Style>
<Style BasedOn="{StaticResource Text-Light}" />
</Border.Style>
<StackPanel Orientation="Horizontal"
VerticalAlignment="Center">
<ContentPresenter HorizontalAlignment="Left"
VerticalAlignment="Center" />
<Label Style="{StaticResource TabTextChevron}" />
</StackPanel>
</Border>
</ControlTemplate>
</RadioButton.Template>
</RadioButton>
选中时,我想改变Border
的背景,因为这是视觉元素,构成了控制。
我已将触发器放在ControlTemplate
上,以触发属性IsChecked
。但是,这意味着我无法在触发器中设置Border
(例如https://stackoverflow.com/a/7965739/4456875)。
如果我在边界上放置触发器,我无法获得IsChecked
属性,因为Border
上没有这种东西。
如果需要在IsChecked
上触发,RadioButton
应如何模板化?
我知道这将是简单的... –