开发者

Windows Phone - Change Grid Background Color On Button Click

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.

Thanks.


In the event handler for the button's Click event add the following:

LayoutRoot.Background = new SolidColorBrush( Colors.Cyan );

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.

In XAML

<Grid Background="{Binding RootBackground}">
...
</Grid>

In your ViewModel

public Brush RootBackground
{
  get { return _rootBackground; }
  set 
  {
    if( value != _rootBackground ) {
      _rootBackground = value;
      NotifyPropertyChanged( "RootBackground" );
    }
   }
}
private Brush _rootBackground = new SolidColorBrush( Colors.Transparent );

In the button event handler

RootBackground = new SolidColorBrush( Colors.Cyan );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜