【问题标题】:Set custom theme with default page background in WP7.1 Mango在 WP7.1 Mango 中使用默认页面背景设置自定义主题
【发布时间】:2012-04-27 07:49:43
【问题描述】:

我正在创建一个 WP Mango 应用。我想将默认页面背景设置为白色,无论选择浅色或深色主题,就像默认邮件应用程序一样。 我已经关注this article 并尝试将默认的 PhoneBackgroundBrush 更改为:

(Application.Current.Resources["PhoneBackgroundBrush"]as SolidColorBrush).Color = Colors.White;

知道我做错了什么或如何实现吗?

【问题讨论】:

  • 怎么了?它不工作?你有错误吗?怎么了?您在代码中的什么位置放置了这一行?
  • @KooKiz 我将这一行放在 App 类的构造函数中。虽然设置其他画笔(例如 PhoneForegroundBrush 或 PhoneAccentBrush 有效,但设置 PhoneBackgroundBrush 似乎没有任何效果。我有什么方法可以为我的应用设置“Light”主题吗?
  • @Soap 看起来在那个例子中也不起作用——他的代码将它设置为紫色,但在结尾的图片中背景绝对不是紫色

标签: windows-phone-7.1 windows-phone-7


【解决方案1】:

我弄乱了示例,根本不建议这样做。做额外的工作,创建自己的资源,然后自己应用它们。

此方法不会在设计器中显示更新,这会使您的 UI 开发变得困难。

它甚至不能正常工作——背景没有改变。如果您阅读了博客文章中的 cmets,那么它与其他控件一起使用时会出现其他问题。

所以,只需正常执行 - 在您的 App.xaml 中(您也可以在单独的 ResourceDictionary 中执行)

 <!--Application Resources-->
<Application.Resources>
    <SolidColorBrush Color="White" x:Key="WhiteBrush" />
    <SolidColorBrush Color="#FFF222" x:Key="UglyYellowBrush" />
</Application.Resources>

然后,在页面上

 <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="{StaticResource UglyYellowBrush}">
 ... </Grid>

如果您从未更改过名称“LayoutRoot”,您甚至可以使用“查找和替换”在所有页面上快速执行此操作。如果你发现

 <Grid x:Name="LayoutRoot" Background="Transparent">

你可以换成

<Grid x:Name="LayoutRoot" Background="{StaticResource UglyYellowBrush}">

【讨论】:

    【解决方案2】:

    创建自己的风格的解决方案对我不起作用。我尝试将背景设置为在设计视图中有效的浅灰色,但是当我运行模拟器时,出现了标准的黑色背景。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-11
      • 1970-01-01
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      相关资源
      最近更新 更多