wpf - 如何更改 WPF 工具栏下拉按钮的背景颜色?
问题描述
如何更改 WPF 工具栏下拉按钮的背景颜色?
更新:
XAML 代码:
<Window x:Class="WpfTutorialSamples.Common_interface_controls.ToolbarSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ToolbarSample" Height="200" Width="300">
<DockPanel>
<ToolBarTray DockPanel.Dock="Top">
<ToolBar>
<Button Content="New" />
<Button Content="Open" />
<Button Content="Save" />
</ToolBar>
<ToolBar Background="GreenYellow">
<Button Content="Cut" />
<Button Content="Copy" />
<Button Content="Paste" />
</ToolBar>
</ToolBarTray>
<TextBox Text="Test" />
</DockPanel>
</Window>
解决方案
用户可以在 ToolBarAdv 中自定义溢出按钮颜色。可以通过在 ToolBarAdv 中编辑 ToggleButton Style 来实现。下面的代码演示了相同的。
<Style TargetType="{x:Type ToggleButton}">
<!--Set Overflow Button backcolor -->
<Setter Property="Background" Value="Yellow" />
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static
SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="Chrome" Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" CornerRadius="0,3,3,0">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}" RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" Value="0.3"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
推荐阅读
- c++ - 如何使用参数将 std::string 复制到 std::string?
- android - 重新启动 Fragment 是否还会召回 FirebaseDatabase
- reactjs - 在 MaterialTable ui https://material-table.com/#/docs/features/localization 上设置分页?
- python - 有没有更好的方法在 Pandas/Python 中实现匹配算法?
- c# - 使用 C# 和 LightGBM 的基于 GPU 的二进制分类是否可行(还没有?)
- laravel - phpunit 测试 - 断言两个字符串相等失败
- javascript - _co.onImagePicked 不是函数错误
- c# - 使用 Visual Studio 2019 C# 的 gRPC 构建错误
- arrays - 如何验证数组中的每个元素是否包含打字稿/量角器中的搜索字符串
- css - 字体真棒图标未显示