Windows Phone的 - 更改网格背景颜色按钮单击 [英] Windows Phone - Change Grid Background Color On Button Click
问题描述
我试图更改名为网格的背景色 LayoutRoot
为黑色,当您单击按钮 bgButton
应用程序栏中。我无法找到如何通过谷歌或任何做这种事。
I'm trying to change the background color of the grid named LayoutRoot
to black when you click the button bgButton
in the application bar. I can't find anything on how to do this through Google or anything.
感谢。
推荐答案
在该按钮的<事件处理程序code>点击事件中添加以下内容:
In the event handler for the button's Click
event add the following:
LayoutRoot.Background = new SolidColorBrush( Colors.Cyan );
它并不必须是一个 的SolidColorBrush
,它可以是从 刷
,如的 一个LinearGradientBrush
,的 放射
等
It doesn't have to be a SolidColorBrush
, it can be any class derived from Brush
, such as LinearGradientBrush
, RadialGradientBrush
etc.
您也可以使用绑定的,而不是明确设置为网格颜色
。
You can also use a binding instead of explicitly setting the color for the Grid
.
在XAML
<Grid Background="{Binding RootBackground}">
...
</Grid>
在您的视图模型
public Brush RootBackground
{
get { return _rootBackground; }
set
{
if( value != _rootBackground ) {
_rootBackground = value;
NotifyPropertyChanged( "RootBackground" );
}
}
}
private Brush _rootBackground = new SolidColorBrush( Colors.Transparent );
在按钮的事件处理程序
RootBackground = new SolidColorBrush( Colors.Cyan );
这篇关于Windows Phone的 - 更改网格背景颜色按钮单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!