繁体   English   中英

如何在wp7应用程序中更改xaml页面的背景颜色?

[英]How to change the background color of xaml page in wp7 application?

我正在开发windows phone 7应用程序。 我是窗口手机7应用程序的新手。 我想在window phone 7应用程序中更改整个xaml页面的背景颜色。 我在xaml页面的构造函数中尝试了以下代码

 this.Background = new SolidColorBrush(Colors.White);

但它没有用。

我还在手机中添加了属性:PhoneApplicationPage标签如下

<phone:PhoneApplicationPage 
Background="Red"

但它也没有用。 能否请您提供任何代码或链接或解决上述问题的解决方案? 如果我做错了什么,请指导我。

您可以在页面上设置最外层控件的Background属性。 对于在WP7中创建的默认页面,该页面将是名为Layout的网格。

如果要查看效果,则需要更改LayoutRoot的背景:

<Grid x:Name="LayoutRoot" Background="YellowGreen">
..

也许主题不尊重页面中的背景颜色。 您可以做的是添加边框作为页面的子项,并将其背景颜色设置为您想要的任何颜色。

<phone:PhoneApplicationPage> 
<Border Background="Red">
...more content here...
</Border>
</phone:PhoneApplicationPage> 

有一些选项可以设置页面或网格的背景。

假设您的xaml页面如下所示

<Grid x:Name="LayoutRoot">  
  //start from here page design
</Grid>
  1. 如果要从xaml设置页面,请使用以下代码。 有一些选项可以设置页面或网格的背景

     <Grid x:Name="LayoutRoot"> //start from here page design </Grid> 
  2. 如果想从.cs文件设置,请在构造函数InitializeComponent();使用下面的代码InitializeComponent(); 初始化页面的方法。

     public MainPge() { InitializeComponent(); LayoutRoot.Background = new SolidColorBrush(Colors.White); } 
  3. 对于所有页面,在app.xaml.cs中添加以下代码(仅测试WP8.1 silverlight)

     public PhoneApplicationFrame RootFrame { get; private set; } public App() { .............. RootFrame = new TransitionFrame { Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF)) }; } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM