我在win表單應用程序中構建了一些WPF頁面。我希望爲我的應用程序使用WPF主題。不具有App.xaml
(因爲這個項目是一個雙贏的形式項目用WPF ElementHost
展現WPF形式),我說我的主題資源字典在我的形式是這樣的:在WPF中定義其他資源clobbers主題
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes/ExpressionDark.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
這適用於所有控件這張表格上加上一些其他的WPF用戶控件,但有些用戶控件的主題不起作用。我已經找到了這是這樣定義自己的資源受影響的控件:這似乎
<Grid.Resources>
<Style TargetType="ComboBox">
<Setter Property="Margin" Value="0 2 5 2" />
</Style>
</Grid.Resources>
並不無論身在何處的資源都位於或什麼是資源。資源中沒有鍵控的任何東西都會阻止所有樣式目標的主題。我甚至嘗試了智能通過它在字典中查找資源:
<Style TargetType="{x:Type ComboBox}">
<Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="Template" Value="{DynamicResource ComboBoxTemplate}" />
</Style>
和修改我的風格,看起來像這樣:
<Grid.Resources>
<Style TargetType="ComboBox">
<Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="Template" Value="{DynamicResource ComboBoxTemplate}" />
<Setter Property="Margin" Value="0 2 5 2" />
</Style>
</Grid.Resources>
但是,這引起了我的組合框完全消失!
有什麼方法可以添加覆蓋目標控件的資源並且不會拋棄主題?
@戴夫克萊默,爲什麼你會從更具體的'WPF的styles'的東西編輯標籤一些不太具體的'樣式'?這似乎是一個非常糟糕的主意! –
我將其重新標記爲樣式,以便更多人可以找到這篇文章,因爲在wpf樣式下幾乎沒有任何東西會出現。我被告知wpf-標籤正在泄氣。無論如何,標籤描述應該反映這一點。 –
有趣。這個問題是當人們選擇標籤來跟着你不能說'wpf'和'樣式',所以你可能會得到網絡,android,delphi等,但我想我不會制定規則。 –