如何更改wp7应用程序中xaml页面的背景颜色?
我正在开发 Windows Phone 7 应用程序。我是 Windows Phone 7 应用程序的新手。我想更改window Phone 7应用程序中整个xaml页面的背景颜色。我在 xaml 页面的构造函数中尝试了以下代码
this.Background = new SolidColorBrush(Colors.White);
,但它不起作用。
我还在phone:PhoneApplicationPage 标记中添加了属性,如下所示
<phone:PhoneApplicationPage
Background="Red"
,但它也不起作用。您能否向我提供任何代码或链接或任何可以解决上述问题的解决方案?如果我做错了什么,请指导我。
I am developing window phone 7 application. I am new to the window phone 7 application. I want to change the background color of the entire xaml page in the window phone 7 application. I have tried the following code in the constructor of the xaml page
this.Background = new SolidColorBrush(Colors.White);
But it is not working.
I have also added the attribute in the phone:PhoneApplicationPage tag as follows
<phone:PhoneApplicationPage
Background="Red"
But it is also not working. Can you please provide me any code or link or any solution through which I can resolve the above issue? If I am doing anything wrong then please guide me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以设置页面上最外层控件的Background 属性。对于在 WP7 中创建的默认页面,该页面将是一个名为“布局”的网格。
如果想看到效果,需要改变LayoutRoot的背景:
You can set the Background property of the outermost control on the page. For a default page created in WP7 that would be a Grid named Layout.
You need to change the background of the LayoutRoot if you want to see the effect:
也许主题不尊重页面中的背景颜色。您可以做的是将边框添加为页面的子项,并将其背景颜色设置为您想要的任何颜色。
Maybe the theme does not respect the background color in the page. What you can do is add A border as a child of the page and set its background color to whatever you want.
有一些选项可以设置页面或网格的背景。
假设您的 xaml 页面如下所示
如果您想从 xaml 设置页面,请使用以下代码。有一些选项可以设置页面或网格的背景
如果想从 .cs 文件设置,请在构造函数
InitializeComponent();
初始化页面的方法中使用以下代码。对于所有页面,在 app.xaml.cs 中添加以下代码(仅测试 WP8.1 silverlight)
There are some options to set background of a page or grid.
suppose your xaml page is like below
If you want to set page from xaml then use following code. There are some options to set background of a page or grid
If want to set from .cs file use below code at constructor
InitializeComponent();
methods which initialize page.For all pages add following code at app.xaml.cs (tested only WP8.1 silverlight)