问题主要出在 样式里面的 Trigger 当中,我当时是要在 Trigger 里直接修改 Content ,给 Checked 的按钮加上一个 √ 。结果发现不同 GroupName 的 RadioButton 居然不能正确分组,所有使用该自定义控件的 RadioButton 在 UI 效果上都属于同一组,都会产生互斥选择。
这个问题排查了很久,一开始以为是自定义的按钮逻辑产生了问题,最后才发现居然是 UI 这里的 Trigger 造成的。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:HLControls">
<Style TargetType="{x:Type local:ColorRadioButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ColorRadioButton}">
<Border x:Name="border"
Background="{TemplateBinding ColorBrush}"
BorderBrush=