WPF如何覆盖/设置RibbonMenuButton中的复选框的样式

时间:2019-01-17 19:14:31

标签: wpf

我有一个RibbonMenuButton,我试图在ItemContainerStyle下设置复选框的样式,我的问题是我不知道如何进入checkbox属性对其进行样式设置。

当我单击RibbonMenuButton时,ItemContainerStyle的默认默认设置是如何,它将在左侧带有复选框的情况下显示项目。而且在ItemContainerStyle下没有CheckBox属性可供我覆盖该复选框。所以我尝试使用Icon属性(假设它将以某种方式更改复选框样式)

 <RibbonMenuButton.ItemContainerStyle>
    <Style TargetType="RibbonMenuItem">
        <Setter Property="IsCheckable"
                Value="True" />
        <Setter Property="IsChecked"
                Value="{Binding IsChecked}" />
        <Setter Property="Header"
                Value="{Binding Content}" />
        <Setter Property="ToolTipTitle"
                Value="{Binding Content}" />
        <Setter Property="ToolTipDescription"
                Value="{Binding ToolTip}" />
        <Setter Property="CheckedBorderBrush"
                Value="Black"/>
        <Setter Property="CheckedBackground"
                Value="White"/>
        <Setter Property="Icon">
            <Setter.Value>
                <CheckBox>
                    <ControlTemplate TargetType="RibbonMenuItem">
                        <BulletDecorator Background="Red">
                            <BulletDecorator.Bullet>
                                <Border x:Name="Border"
                                BorderBrush="Pink"
                                BorderThickness="1"
                                ClipToBounds="True">
                                    <Grid>
                                        <TextBlock Visibility="Hidden"
                                           Text="AA"/>
                                        <Path x:Name="CheckMark"
                                      Visibility="Hidden"
                                      Data="M 0 5 L 3 8 M 3 8 L 8 0"
                                      Stretch="Uniform"
                                      Stroke="{TemplateBinding Foreground}"
                                      StrokeEndLineCap="Round"
                                      StrokeStartLineCap="Round"
                                      Margin="2"
                                      StrokeThickness="2" />
                                        <Rectangle x:Name="IndeterminateMark"
                                           Fill="{TemplateBinding Foreground}"
                                           Visibility="Hidden"
                                           Margin="3" />
                                    </Grid>
                                </Border>
                            </BulletDecorator.Bullet>
                            <ContentPresenter Margin="4,0,0,0"
                                      VerticalAlignment="Center"
                                      HorizontalAlignment="Left"
                                      RecognizesAccessKey="True" />
                        </BulletDecorator>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked"
                             Value="True">
                                <Setter TargetName="CheckMark"
                                Property="Visibility"
                                Value="Visible" />
                            </Trigger>
                            <Trigger Property="IsChecked"
                             Value="True">
                                <Setter TargetName="IndeterminateMark"
                                Property="Visibility"
                                Value="Visible" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </CheckBox>

            </Setter.Value>
        </Setter>
    </Style>
</RibbonMenuButton.ItemContainerStyle>

当我应用Icon属性时,什么都没有改变。我唯一可以更改复选框的是CheckedBorderBrush和CheckedBackground属性

0 个答案:

没有答案