2
我寫了一個小測試用例,用於某些我不太明白的行爲。如果有人能爲我解決這個問題,我會非常感興趣。覆蓋以前在應用程序資源中定義的新窗口中的邊框樣式(可能是bug?)
我有,在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>
我我的印象是,如果我要重新定義樣式,如上所述,這將覆蓋我放入應用程序資源的內容。我已經測試過設置邊界刷無效,即使這不應該是必需的。
下面是我曾以爲那裏是沒有邊界的造型窗口的截屏: -
注意這似乎看起來在設計不錯,但不能在運行時。此外,這適用於其他目標類型,除了邊界(用TextBlock和其他幾個控件測試)
是的,我調查了這一點;其他人寫了類似的回答,但很快就刪除了。不幸的是,設置邊界刷特性似乎並沒有覆蓋應用程序資源。此外,我的印象是重新定義風格,正如我的例子中的窗口所做的那樣,應該阻擋全球風格。請參閱http://blog.scrappydog.com/2009/02/applying-and-blocking-global-styles-in.html – chrisw 2013-03-20 16:16:24