How to change the background color of xaml page in wp7 application?
Asked Answered
G

3

6

I am developing window phone 7 application. I am new to the window phone 7 application. I want to change the background color of the entire xaml page in the window phone 7 application. I have tried the following code in the constructor of the xaml page

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

But it is not working.

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

<phone:PhoneApplicationPage 
Background="Red"

But it is also not working. Can you please provide me any code or link or any solution through which I can resolve the above issue? If I am doing anything wrong then please guide me.

Gunsel answered 7/2, 2011 at 11:36 Comment(0)
V
8

You can set the Background property of the outermost control on the page. For a default page created in WP7 that would be a Grid named Layout.

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

<Grid x:Name="LayoutRoot" Background="YellowGreen">
..
Vudimir answered 7/2, 2011 at 11:51 Comment(0)
O
1

Maybe the theme does not respect the background color in the page. What you can do is add A border as a child of the page and set its background color to whatever you want.

<phone:PhoneApplicationPage> 
<Border Background="Red">
...more content here...
</Border>
</phone:PhoneApplicationPage> 
Olympie answered 7/2, 2011 at 11:45 Comment(0)
S
0

There are some options to set background of a page or grid.

suppose your xaml page is like below

<Grid x:Name="LayoutRoot">  
  //start from here page design
</Grid>
  1. If you want to set page from xaml then use following code. There are some options to set background of a page or grid

    <Grid x:Name="LayoutRoot">  
      //start from here page design
    </Grid>
    
  2. If want to set from .cs file use below code at constructor InitializeComponent(); methods which initialize page.

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

    public PhoneApplicationFrame RootFrame { get; private set; }
    public App()
    {
       ..............
    
       RootFrame = new TransitionFrame
       { 
          Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF))
       };
    }
    
Sentiment answered 4/2, 2017 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.