【问题标题】:windows phone 7: how to create an application theme?windows phone 7:如何创建应用程序主题?
【发布时间】:2010-09-16 10:36:48
【问题描述】:

我想为我的 Windows Phone 7 应用程序定义一个主题,以便在应用程序启动时应用,而不管“设置”手机菜单设置的系统主题是什么。如何做到这一点?

我在 MSDN 上看到 Fill="{StaticResource PhoneAccentBrush}" 允许控件使用该画笔来响应系统范围的主题更改。我怎么能做同样的事情:允许控件获取它的画笔,而不是从系统设置,而是从我的应用程序设置?

我应该将这些设置放在哪里,以便拥有一个可以从应用程序中的任何位置访问的样式设置文件?

【问题讨论】:

    标签: themes windows-phone-7 styles


    【解决方案1】:

    Silverlight 中没有特定于主题的 API。您拥有的是一个或多个资源字典,您可以使用它们来定义一组要应用于您的控件的样式。

    在 Theme1.xaml 文件中:

    <Style x:Key="HeadingStyle" TargetType="{x:Type Label}">
         <Setter Property="Foreground" Value="Black"/>
    </Style>
    

    在 Theme2.xaml 文件中:

    <Style x:Key="HeadingStyle" TargetType="{x:Type Label}">
      <Setter Property="Foreground" Value="Red"/>
    </Style>
    

    在 App.xaml(默认主题或引用 default.xaml 文件)中:

    <Application.Resources>
       <Style x:Key="HeadingStyle" TargetType="{x:Type Label}">
        <Setter Property="Foreground" Value="blue"/>
      </Style>
    </Application.Resources>
    

    改变当前的“主题”:

    Application.Current.Resources = Application.LoadComponent(new Uri("Theme2.xaml", UriKind.RelativeOrAbsolute));
    

    我现在没有安装 RTM 工具,所以我无法测试这段代码。

    【讨论】:

    猜你喜欢
    • 2011-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多