如何在功能区分割按钮中更改togglebutton的样式

问题描述 投票:0回答:1

我做了一个ribbonplitbutton。但我不知道我如何更改功能区分割按钮中使用的togglebutton的背景颜色。我到目前为止所做的代码是这样的

<Custom:RibbonSplitButton LargeImageSource="Images\folder.jpg" Label="Open" HorizontalAlignment="Left" VerticalAlignment="Top" >
            <Custom:RibbonMenuItem  Header="find" ImageSource="Images\find.png"/>
            <Custom:RibbonMenuItem  Header="copy" ImageSource="Images\copy.png"/>
            <Custom:RibbonMenuItem  Header="calculator" ImageSource="Images\calculator.png"/>
            <Custom:RibbonMenuItem  Header="setting" ImageSource="Images\Setting.png"/>
            <Custom:RibbonMenuItem  Header="calender" ImageSource="Images\calender.png"/>
            <Custom:RibbonMenuItem  Header="print" ImageSource="Images\print.png"/>

</Custom:RibbonSplitButton>

有人可以帮助我为togglebutton创建一个样式。

wpf wpf-controls
1个回答
0
投票

您可以通过更改part_toggle按钮的样式来更改功能区分割按钮中的切换按钮的样式,样式的示例代码是

<Border x:Name="UnderlayBorder" Background="{Binding MouseOverBackground, RelativeSource={RelativeSource TemplatedParent}}" Opacity="0.5" Visibility="Collapsed"/>
                                            <Custom:RibbonToggleButton x:Name="PART_ToggleButton" BorderBrush="{TemplateBinding BorderBrush}" Background="Transparent" ToolTipService.BetweenShowDelay="0" CheckedBackground="{TemplateBinding CheckedBackground}" ClickMode="Press" CornerRadius="0,2,2,0" CheckedBorderBrush="{TemplateBinding CheckedBorderBrush}" FocusedBackground="{TemplateBinding FocusedBackground}" FocusedBorderBrush="{TemplateBinding FocusedBorderBrush}" FocusVisualStyle="{x:Null}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" ToolTipService.InitialShowDelay="900" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Label="{TemplateBinding Label}" MouseOverBackground="{TemplateBinding MouseOverBackground}" MouseOverBorderBrush="{TemplateBinding MouseOverBorderBrush}" PressedBorderBrush="{TemplateBinding PressedBorderBrush}" Padding="{TemplateBinding Padding}" PressedBackground="{TemplateBinding PressedBackground}" Custom:RibbonTwoLineText.PathData="M0,0L2.5,3 5,0z" Style="{x:Null}" ToolTipService.ShowDuration="20000" ToolTipDescription="{TemplateBinding DropDownToolTipDescription}" ToolTipFooterDescription="{TemplateBinding DropDownToolTipFooterDescription}" ToolTipImageSource="{TemplateBinding DropDownToolTipImageSource}" ToolTipFooterTitle="{TemplateBinding DropDownToolTipFooterTitle}" ToolTipFooterImageSource="{TemplateBinding DropDownToolTipFooterImageSource}" ToolTipTitle="{TemplateBinding DropDownToolTipTitle}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}">
                                                <Custom:RibbonToggleButton.ControlSizeDefinition>
                                                    <Custom:RibbonControlSizeDefinition IsLabelVisible="False" ImageSize="Collapsed"/>
                                                </Custom:RibbonToggleButton.ControlSizeDefinition>
                                                <Custom:RibbonToggleButton.Template>
                                                    <ControlTemplate TargetType="{x:Type Custom:RibbonToggleButton}">
                                                        <Grid x:Name="MainGrid" SnapsToDevicePixels="True">
                                                            <Border x:Name="OuterBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding CornerRadius}"/>
                                                            <Border x:Name="MiddleBorder" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent" CornerRadius="{TemplateBinding CornerRadius}">
                                                                <Border x:Name="InnerBorder" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent" CornerRadius="{TemplateBinding CornerRadius}" Padding="{TemplateBinding Padding}">
                                                                    <StackPanel x:Name="StackPanel" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                                                        <Image x:Name="PART_Image" RenderOptions.BitmapScalingMode="NearestNeighbor" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Height="32" Margin="{DynamicResource {ComponentResourceKey ResourceId=LargeImageMargin, TypeInTargetAssembly={x:Type Custom:Ribbon}}}" Source="{TemplateBinding LargeImageSource}" VerticalAlignment="Center" Width="32"/>
                                                                        <Grid x:Name="Grid" HorizontalAlignment="Left" VerticalAlignment="Top" >
                                                                            <Custom:RibbonTwoLineText x:Name="TwoLineText" Custom:RibbonTwoLineText.HasTwoLines="{TemplateBinding Custom:RibbonTwoLineText.HasTwoLines}" HorizontalAlignment="Center" LineStackingStrategy="BlockLineHeight" LineHeight="5" Margin="1,1,1,0" PathFill="{TemplateBinding Foreground}" Custom:RibbonTwoLineText.PathData="{TemplateBinding Custom:RibbonTwoLineText.PathData}" TextAlignment="Center" Text="{TemplateBinding Label}" VerticalAlignment="Top"/>
                                                                        </Grid>
                                                                    </StackPanel>
                                                                </Border>
                                                            </Border>
                                                        </Grid>
© www.soinside.com 2019 - 2024. All rights reserved.