我有兩個畫筆在我的ResourceDictionary中聲明,我希望用戶選擇他們想要在主窗口上看到的背景。設置WPF窗口背景資源字典刷用戶設置
資源字典刷子:
x:Key="LightBlueMainWindow"
x:Key="DarkBlueMainWindow"
窗口:
Background="{DynamicResource LightBlueMainWindow}">
我有一個項目用戶設置定義的 'MainBackground',這是一個字符串,並可以包含密鑰(LightBlueMainWindow或DarkBlueMainWindow )。
根據XAML中的用戶設置動態設置背景的最佳方法是什麼?
編輯
我需要一提的是,我需要從許多不同的用戶控件和窗口的整個應用程序訪問此刷。我不想在每個我想設置此畫筆的地方設置屬性。
此外,電刷是預先定義的,而不僅僅是像這樣
<LinearGradientBrush x:Key="LightBlueMainWindow" EndPoint="0.5,1"
MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFE9EFF3" />
<GradientStop Color="#FF84A1B8" Offset="1"/>
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
也許我錯過了你的問題,你想只指定一次,然後它應該爲應用程序中的所有Windows和UserControls設置?我理解它就像你想能夠指定MainBackground字符串作爲背景的資源鍵.. –