在先前在Application Resources中定义的新窗口中覆盖Border样式(可能是bug?)

时间:2013-03-20 14:03:34

标签: c# wpf xaml

我为一些我不太了解的行为编写了一个小测试用例。如果有人能为我解决这个问题,我最感兴趣的是。

我有,在App.xaml中,

<Application x:Class="WpfApplication1.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="Border">
      <Setter Property="BorderBrush"
          Value="Crimson" />
    </Style>
  </Application.Resources>
</Application>

我想删除以下窗口的样式,以便重新定义样式,如下所示: -

<Window x:Class="WpfApplication1.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">

  <ListView>
    <ListView.Resources>
      <Style TargetType="Border" />
     </ListView.Resources>
     <ListView.View>
       <GridView>
         <GridViewColumn Header="test1" />
         <GridViewColumn Header="test2" />
       </GridView>
     </ListView.View>
  </ListView>
</Window>

我的印象是,如果我要重新定义样式,如上所述,这将覆盖我放在应用程序资源中的内容。我已经测试过设置边框刷无效,即使这不是必需的。

下面是我假设没有边框样式的窗口的屏幕截图: -

Test case window

注意它似乎在设计器中看起来很好但在运行时却没有。此外,这适用于其他目标类型EXCEPT border(使用TextBlock和一些其他控件测试)

1 个答案:

答案 0 :(得分:0)

您是否尝试使用在ListView资源中声明的样式为BorderBrush添加setter?