[英]Make WPF button look less flat
I've got 2 buttons on my form, and they both look very, very flat. 我的表单上有2个按钮,它们看上去都非常非常平坦。
I can't seem to find a way to make them look more like: 我似乎找不到一种使它们看起来更像的方法:
The XAML for my buttons is: 我的按钮的XAML是:
<Button x:Name="bttnDailyReport" HorizontalAlignment="Left" Margin="618,27,0,0" VerticalAlignment="Top" Width="121" Height="93" FontFamily="Microsoft Sans Serif" FontSize="20" FontWeight="Bold" Grid.Column="1" BorderBrush="Black">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"><Run Text=" Generate"/><LineBreak/><Run Text="Daily Report"/></TextBlock>
</Button>
<Button x:Name="bttnCancel" HorizontalAlignment="Left" Margin="618,126,0,0" VerticalAlignment="Top" Width="121" Height="93" FontFamily="Microsoft Sans Serif" FontSize="20" FontWeight="Bold" Click="BttnCancelClick">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"><Run Text="Exit"/></TextBlock>
</Button>
Now, my question is, is it possible to make the buttons appear like the button in WinForms, or am I stuck with flat buttons? 现在,我的问题是,是否有可能使按钮看起来像WinForms中的按钮,还是我只能使用平面按钮?
Seems, somewhere in your resources, flat button style is used as default style for button. 似乎在资源中的某个地方,扁平按钮样式用作按钮的默认样式。
Check Styling and Templating . 检查样式和模板 。 Either you need to override the style in your button, or give key to the default style, and apply wherever needed. 您需要覆盖按钮中的样式,或者将键赋予默认样式,然后在需要的地方应用。
How to override a global style (that doesn't have an x:Key), or alternatively apply a named style to all type-targeted controls? 如何覆盖全局样式(没有x:Key),或者将命名样式应用于所有以类型为目标的控件?
Just reference PresentationFramework.Aero.dll
in your project and add this code to to the window's XAML: 只需在您的项目中引用PresentationFramework.Aero.dll
,然后将此代码添加到窗口的XAML中即可:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/aero.normalcolor.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
By default, buttons should look like the second image. 默认情况下,按钮应看起来像第二个图像。 To make sure that there is no "BoringButton" Style around that make your buttons look flat (as Tilak and Chris W suggest), try to explicitly clear your button's Style like this: 为确保周围没有“ BoringButton”样式使您的按钮看起来平整(如Tilak和Chris W所建议的那样),请尝试明确清除按钮的样式,如下所示:
<Button x:Name="bttnDailyReport" Style="{x:Null}" >
Also, don't set your button's Background to a specific color (although that already looks OK in the code you posted). 另外,不要将按钮的背景设置为特定的颜色(尽管在您发布的代码中看起来已经不错)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.