有没有一种方法可以更改所有页面的背景颜色?或者我只需要在每个页面上更改
LayoutRoot
的颜色?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>
Background = new SolidColorBrush( Color.FromArgb( 255, 109, 41, 100 ) );
- Josh Close我已经找到了一个解决方法。
问题在于Mango如何定义页面的背景颜色。
唯一的解决方法是使用应用程序范围内的样式,并将其应用于页面。
这里有一个很好的指南: 逐步定制Windows Phone Mango应用主题
按照这些建议,我甚至能够动态地更改颜色。
<Style TargetType="phone:PhoneApplicationFrame">
<Setter Property="Background" Value="{StaticResource SomeBrush}"/>
</Style>