1 Replies - 10967 Views - Last Post: 20 October 2011 - 12:44 PM

#1 complete  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 108
  • Joined: 12-April 07

defining a BorderBrush

Posted 20 October 2011 - 12:28 PM

I am having some basic compile issues defining a BorderBrush in my Silverlight C# file.

states that you define a borderbrush like this:

myBorder1 = new Border();
myBorder1.BorderBrush = Brushes.SlateBlue;

but in my code, when I try
border1.BorderBrush = Brushes.SlateBlue;

I get


Error 1 The name 'Brushes' does not exist in the current context

and I have included the namespace
as a "using" statement at the top of the file
as well as a Reference to the project.
What am I missing?

Is This A Good Question/Topic? 0
  • +

Replies To: defining a BorderBrush

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1532
  • View blog
  • Posts: 5,969
  • Joined: 21-March 08

Re: defining a BorderBrush

Posted 20 October 2011 - 12:44 PM

Sadly, the Brushes class doesn't exist in Silverlight. It's a very weird decision by Microsoft since the values are available in XAML, just not in the code-behind.

To do what you want, you will need to do a couple of things.

Add this class to your project.

This class will add an extension method and a new enum. This enum will give you all of the colors available in Silverlight, just like in XAML. The extension method will convert the ColorNames enum value to an actual Color object so it can be used in Silverlight methods.

So now, in your code, you will use the enum value that you want, then call the extension method like this...

myBorder1 = new Border();
myBorder1.BorderBrush = new SolidColorBrush(ColorNames.SlateBlue.ToColor());

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1