This question crops up from time to time. “Why is my Silverlight Usercontrol background always White?”.
Take this simple example.
<UserControl x:Class="Blog.WpfWonderland.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background='Orange'> <Grid x:Name="LayoutRoot"> </Grid> </UserControl>
Run this example and you get a white page. To be more precise you will get a page that is the color specified in the host page. Change the color of the background in the host page object tag as shown below and you will see a green page. Still no orange colored UserControl.
<object data="data:application/x-silverlight-2,"
type="application/x-silverlight-2" width="100%" height="100%"> <param name="background" value="green" />
The solution is simple as seen below.
<!– The solution.
Assign the background brush to a top level Panel that is set to be the same size as the parent UserControl--> <Grid x:Name="LayoutRoot" Background='Orange'> <!-- put the rest of your UI in another panel --> <Grid Width='200' Height='300'
Background='Yellow'> </Grid> </Grid>
