【发布时间】:2014-04-24 14:08:52
【问题描述】:
我有 2 个 XAML 文件:MainPage.xaml 和 Settings.XAML
我想从 Settings.XAML 更改 MainPage.xaml LayoutRoot.Background 属性。做这个的最好方式是什么?
【问题讨论】:
标签: c# xaml windows-phone-8
我有 2 个 XAML 文件:MainPage.xaml 和 Settings.XAML
我想从 Settings.XAML 更改 MainPage.xaml LayoutRoot.Background 属性。做这个的最好方式是什么?
【问题讨论】:
标签: c# xaml windows-phone-8
创建资源字典。使用这些内容在您的项目中创建一个新的 xaml 文件(例如 Style.xaml)
<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。顺便说一句,如果您想将设置拆分为不同的文件,您可以将每个文件放在此 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>
现在您应该可以像这样在 MainPage.xaml 中使用 MainBackGroundColor
Background="{StaticResource MainBackGroundColor}"
【讨论】: