Пытаюсь сделать стиль для CheckBox'а с границами разного цвета. Но, не понимаю, почему не работает привязка значения Setter'а (BorderThickness) к Rectangle (Width и Height) для масштабирования толщины границ через свойство BorderThickness у CheckBox'а.
XAML:
<Window.Resources>
<Style x:Key="CheckBoxStyle1" TargetType="{x:Type CheckBox}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Background" Value="#5333"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True">
<DockPanel x:Name="checkBoxBorder" LastChildFill="False" Background="{TemplateBinding Background}">
<Rectangle Fill="Yellow" DockPanel.Dock="Left" Width="{TemplateBinding BorderThickness}"/>
<Rectangle Fill="Red" DockPanel.Dock="Top" Height="{TemplateBinding BorderThickness}"/>
<Rectangle Fill="Green" DockPanel.Dock="Right" Width="{TemplateBinding BorderThickness}"/>
<Rectangle Fill="Blue" DockPanel.Dock="Bottom" Height="{TemplateBinding BorderThickness}"/>
</DockPanel>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid Background="#5777">
<CheckBox Width="200" Height="200" Style="{DynamicResource CheckBoxStyle1}" BorderThickness="5"/>
</Grid>
new Rectangle().Width = new CheckBox().BorderThickness, что увидите? Думаю сразу поймете в чем вы накосячили... И да, как сказали выше, вы делаете костыль, ибо за бордюр в WPF отвечаетBorder. – EvgeniyZ Dec 13 '21 at 01:29