2017-07-27 61 views
2

給定一個Settings.settings文件,其中包含一個或多個SolidColorBrush條目,其中包含Application作用域,如何將這些值綁定到XAML樣式模板?基於SolidColorBrush的綁定設置直接在XAML中

舉例來說,我有一個名爲SolidColorBrushMyAppColor作爲#FF0091D2價值和自定義Button風格模板,在這裏我想BackgroundMyAppColor有顏色。我怎樣才能做到這一點?


我已經嘗試添加namespace (?)到XAML文件,就像這樣:

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:properties="clr-namespace:namespace.Properties" 

然後試圖用properties這樣的:

Background="{x:Static properties:Settings.Default.MyAppColor}" 

但它說它不能嵌套類型。

回答

1

Settings.Default是靜態的,MyAppColor屬性不是。 (Settings.Default有效地是一個Singletone)。使用{x:Static}擴展名設置Binding.Source,並照常提供Binding.Path

Background="{Binding Path=MyAppColor, Source={x:Static properties:Settings.Default}}"