How to change background color of xaml page in wp7 application?

I am developing a Windows Phone 7 application. I am new to Windows Phone 7 application. I want to change the background color of the whole xaml page in a Windows Phone 7 application. I tried the following code in the xaml page designer

this.Background = new SolidColorBrush(Colors.White); 

But it does not work.

I also added an attribute in the phone: PhoneApplicationPage tag as follows

 <phone:PhoneApplicationPage Background="Red" 

But it also does not work. Can you provide me any code or link or any solution with which I can solve the above problem? If I am doing something wrong, then please guide me.

+6
background-color windows-phone-7 silverlight xaml
source share
3 answers

You can set the Background property to an external control on the page. For the default page created in WP7, which will be a table with a mask.

You need to change the LayoutRoot background if you want to see the effect:

 <Grid x:Name="LayoutRoot" Background="YellowGreen"> .. 
+8
source share

Perhaps the theme does not take into account the background color on the page. What you can do is add a border as a child of the page and set its background color for what you want.

 <phone:PhoneApplicationPage> <Border Background="Red"> ...more content here... </Border> </phone:PhoneApplicationPage> 
+1
source share

There are several options for setting the background of the page or grid.

suppose your xaml page looks below

 <Grid x:Name="LayoutRoot"> //start from here page design </Grid> 
  • If you want to install the page from xaml, use the following code. There are several options for setting the page background or grid

     <Grid x:Name="LayoutRoot"> //start from here page design </Grid> 
  • If you want to install from a .cs file, use the code below in the InitializeComponent(); constructor InitializeComponent(); that initializes the page.

     public MainPge() { InitializeComponent(); LayoutRoot.Background = new SolidColorBrush(Colors.White); } 
  • For all pages, add the following code to app.xaml.cs (only WP8.1 silverlight tested)

     public PhoneApplicationFrame RootFrame { get; private set; } public App() { .............. RootFrame = new TransitionFrame { Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF)) }; } 
0
source share

All Articles