user3795349
user3795349

Reputation: 324

Change xaml grid background in windows 8 phone c#

I would like to change the background of the grid in C# code but there is an error while doing so.

Here is the code:

gd.Background = new SolidColorBrush(Windows.UI.Colors.Aqua);

The error says I am missing an assembly reference as the namespace "Colors" does not exist.

Or is there another way to change the background colour of a windows phone 8 theme colour?

Upvotes: 2

Views: 973

Answers (3)

EugenSunic
EugenSunic

Reputation: 13733

There is already an answer to this question. I also had issues with the background color and this thread resolved it for me. URL: Changing color of grid in C# (Windows Phone 8)

Upvotes: 1

Amit Bhatiya
Amit Bhatiya

Reputation: 2621

use this:

gd.Background = new SolidColorBrush(Colors.DarkGray);

Upvotes: 1

Chris Shao
Chris Shao

Reputation: 8231

The issue is in your Namespace of Colors. It should be System.Windows.Media.

This is the demo using Colors:

gd.Background = new System.Windows.Media.SolidColorBrush
                         (System.Windows.Media.Colors.Green);

Another way, we can use Color with FromArgb method:

gd.Background = new System.Windows.Media.SolidColorBrush
                         (System.Windows.Media.Color.FromArgb(0xFF, 0x00, 0xFF, 0x00));

we should set A R G B for it, it's from 0x00 to 0xFF.

Upvotes: 1

Related Questions