相关疑难解决方法(0)

设置 WPF 样式中嵌套元素的属性

我有几种像这样的样式(左、右、中),它们的不同之处仅在于哪些角(如果有)是圆角的。

<Style x:Key="ToggleRadioButtonLeft" 
       TargetType="{x:Type ToggleButton}" 
       BasedOn="{StaticResource {x:Type ToggleButton}}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ToggleButton">
                <Border BorderBrush="Blue" 
                        Background="{TemplateBinding Background}"
                        Padding="15,0" 
                        BorderThickness="1" 
                        CornerRadius="10,0,0,10">  <!-- extract this -->
                    <ContentPresenter HorizontalAlignment="Center"
                                      VerticalAlignment="Center"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Triggers>
        <Trigger Property="IsChecked" Value="True">
            <Setter Property="Background" Value="Blue"/>
            <Setter Property="Foreground" Value="White"/>
        </Trigger>
        <Trigger Property="IsChecked" Value="False">
            <Setter Property="Background" Value="White"/>
            <Setter Property="Foreground" Value="Black"/>
        </Trigger>
    </Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud)

我希望能够创建一个没有圆角的单一基本样式(即中心按钮样式),然后基于它创建另外两个基本样式,为左侧和最右侧的元素设置圆角,但我无法弄清楚如何在派生样式中设置边框半径,因为它不是样式中的顶级元素。

wpf xaml

4
推荐指数
1
解决办法
4012
查看次数

标签 统计

wpf ×1

xaml ×1