WPF : Custom Button

标签 wpf xaml button wpf-controls

我尝试像这样在 wpf 中编辑样式:

enter image description here

允许用户设计,像这样

enter image description here

但是当我尝试创建自己的样式时,有 chrome 层而不是模板,我无法创建自己的按钮,我只能修改简单的值,如 brush ,......

enter image description here

最佳答案

Milad 只需删除该 chrome 层并在模板中包含边框(编写您自己的鼠标悬停和单击触发器):

<Border x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>

触发器:

<ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" TargetName="Chrome" Value="Blue"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="#ADADAD"/>
                            </Trigger>
                        </ControlTemplate.Triggers>

关于WPF : Custom Button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30717185/

相关文章:

c# - 具有多个类类型的单个组合 C# 列表

c# - 带集合的 MVVM 模型。在模型中使用或不使用 observablecollection

c# - 使用 WPF 自定义控件库 (.NET Framework) 中普通 WPF 项目中的 App.xaml

c# - 在 Xamarin.Forms 中绑定(bind)自定义 View

wpf - 通过键入在 Wpf 数据网格中查找记录

css - 如何水平对齐 css Sprite ?

html - 如何在 CSS 中设置菜单样式使其看起来像一个按钮

c# - MVVM C#​​ 在 View (窗口)之间传递数据

android - CursorAdapter 和按钮

WPF Infragistics xamDataGrid - CollectionView GroupDescriptions 无法像 WPF DataGrid 那样被识别