Posted by admin
August - 27 - 2009

Often you want to change the colour when you perform an action to indicate to the user that something has happened. In Silverlight this can be done in may ways including using states, styles and directly changing the controls foreground or background colours.

In this example I am going to have a button inside a StackPanel. When the button is clicked I want the StackPanel’s background to change colour.

private void BtnBgcolor_Click(object sender, RoutedEventArgs e)
{
LayoutRoot.Background = new SolidColorBrush(Colors.HotPink);
}

My StackPanel is called ‘LayoutRoot‘ and I am addressing its background property by passing it a SolidColorBrush. The SolidColorBrush() allows me to pass in a color from the Windows.Media.Colors class.

Download the example from this post and take a look. If you have any issues or questions feel free to discuss them here

About Silverlight Forums

Silverlight Forums Stats

Silverlight Forums is an established Silverlight community for people interested in design and development using Silverlight.

11066 news articles
29 tutorials and 2 video tutorials
2061 forum posts in 1299 threads

Silverlight User Groups (SLUGs)

Why not join your local SLUG?

London, Atlanta, Phoenix, Toronto, Portland, Wellington, Los Angeles, Seattle, South Florida, Tampa Bay, Jacksonville, Belgium

Silverlight Usergroups (SLUGs)