0
更改XAML控制我有2個XAML文件:MainPage.xaml中和Settings.XAML從不同的XAML文件
我想改變從Settings.XAML MainPage.xaml中LayoutRoot.Background財產。做這個的最好方式是什麼?
更改XAML控制我有2個XAML文件:MainPage.xaml中和Settings.XAML從不同的XAML文件
我想改變從Settings.XAML MainPage.xaml中LayoutRoot.Background財產。做這個的最好方式是什麼?
創建一個ResourceDictionary。這些內容
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsm="clr-namespace:System.Windows;assembly=PresentationFramework">
<Color x:Key="MainBackGroundColor">#F6F5E0</Color>
</ResourceDictionary>
更新的App.xaml像這樣在項目中創建一個新的XAML文件(例如Style.xaml)。順便說一下,如果你想將你的設置分成不同的文件,你可以把每個文件放在這個MergedDictionaries部分。現在
<Application x:Class="SonoCine.CineReader.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Style.xaml" />
</ResourceDictionary.
</ResourceDictionary>
</Application.Resources>
</Application>
,你應該能夠使用MainBackGroundColor在MainPage.xaml中這樣
背景= 「{StaticResource的MainBackGroundColor}」
我有點第一踏糊塗。 我只是複製粘貼代碼在xaml文件中的某處? 而且在哪裏? btw這就是我的settings.xaml的樣子:http://pastebin.com/PMyPSDis –
你應該能夠將ResourceDictionary xml剪切/粘貼到名爲Settings.xaml的新文件中。對於App.xaml文件,您可以剪切/粘貼 ResourceDictionary。 ResourceDictionary>並將它放在之間。然後對你的xaml執行此操作。 –
phil
但是Settings.xaml文件已經存在。所以如果我刪除它,那麼我也失去了佈局。 –