更改所有页面WP7的背景颜色

时间:2011-04-09 20:14:40

标签: xaml windows-phone-7

有没有办法更改所有页面的背景颜色?或者我只需要在每个页面上更改LayoutRoot颜色吗?

4 个答案:

答案 0 :(得分:2)

你可以做的是创建一个应用背景颜色的样式,你仍然需要将样式应用到每个页面,但之后如果你需要进行更多的更改,你只需要改变样式。

应用于页面的示例样式可以在Using Styles and Resources to simplify your xaml看到,而不包括背景,它应该很容易理解。

答案 1 :(得分:0)

您可以创建基页类并设置背景颜色,然后从所有其他页面的基页继承。

修改

基页代码:

public class BasePage : PhoneApplicationPage
{
    public BasePage()
    {
        Background = new SolidColorBrush(Colors.Red);
    }
}

主页xaml。请注意,网格会绑定到页面的背景颜色。

<WindowsPhoneApplication2:BasePage
    x:Class="WindowsPhoneApplication2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:WindowsPhoneApplication2="clr-namespace:WindowsPhoneApplication2"
    mc:Ignorable="d"
    d:DesignWidth="480"
    d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="PortraitOrLandscape"
    Orientation="Portrait"
    shell:SystemTray.IsVisible="True"
    x:Name="root">

    <Grid
        x:Name="LayoutRoot"
        Background="{Binding Path=Background, ElementName=root}">

    </Grid>

</WindowsPhoneApplication2:BasePage>

答案 2 :(得分:0)

我找到了解决方案。

问题在于Mango如何定义页面的背景颜色。

唯一的解决方法是使用应用程序范围的样式并将其应用于页面。

这是一个很好的方法:Windows Phone Mango Custom application Theme Step by Step

根据这些建议,我甚至可以动态地改变颜色。

答案 3 :(得分:-1)

添加以下应用程序资源会在所有页面上设置颜色。

<Style TargetType="phone:PhoneApplicationFrame">
    <Setter Property="Background" Value="{StaticResource SomeBrush}"/>
</Style>
相关问题