1

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.

1 Answer 1

3

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 ); 
Sign up to request clarification or add additional context in comments.

3 Comments

Perfect, thanks :) Don't know if you can help with my other question: stackoverflow.com/questions/7563191/…
@Rev Sorry, I've never messed with the camera. Also, you selected my answer before I got a chance to add some more details, so take another look :-)
Ah, that's okay, I'm sure someone will be able to figure it out. And nice, thanks for all that info :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.