【问题标题】:Overriding default style for border makes my WPF window rounded覆盖边框的默认样式使我的 WPF 窗口变圆
【发布时间】:2012-03-04 19:29:02
【问题描述】:

我在 app.xaml 文件中将边框 CornerRadius 覆盖为默认样式(如下所示)

<Application x:Class="BorderCornerProblem.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <Style TargetType="{x:Type Border}">
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="CornerRadius" Value="50"/>  
    </Style>
</Application.Resources>
</Application>

MainWindow.xaml 文件中我有

<Window x:Class="BorderCornerProblem.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">       
</Window>

结果是窗口有一个黑色的圆角。

然后我的问题是如何定义一个 DefaultStyle 并为 Border 设置 CornerRadius 不会弄乱我的窗口?

【问题讨论】:

  • 所以你想改变一些边框样式但不是全部?
  • 嗯,是的。我想为我在 xaml 中显式使用的所有边框设置一种样式

标签: wpf border rounded-corners cornerradius


【解决方案1】:

你真的应该全局样式Borders,它们无处不在。

给样式一个键,只在需要的地方引用它。

【讨论】:

  • 我真的不喜欢你的回答,但它看起来很真实:( DataGrid 也受到我的边框样式的影响。我会用 propper 样式自己控制。谢谢你的帮助
猜你喜欢
  • 1970-01-01
  • 2023-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-20
  • 1970-01-01
  • 1970-01-01
  • 2014-07-18
相关资源
最近更新 更多