top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I set custom colors values in a Xaml Value field?

+1 vote
335 views

hi i am using XAMl for designing i want to know how to set color codes like HTML in XAML any one help how to grab it??

posted Nov 11, 2014 by Puhal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

To paint an area with a solid color, you can use a predefined system brush, such as Red or Blue, or you can create a new SolidColorBrush and describe its Color using alpha, red, green, and blue values. In XAML, you may also paint an area with a solid color by using hexidecimal notation.

The following examples uses each of these techniques to paint a Rectangle blue.

Using a Predefined Brush:

XAML CODE:

 <Rectangle Width="50" Height="50" Fill="Blue" />

C# CODE:

// Create a rectangle and paint it with // a predefined brush.
Rectangle myPredefinedBrushRectangle = new Rectangle();
myPredefinedBrushRectangle.Width = 50;
myPredefinedBrushRectangle.Height = 50;
myPredefinedBrushRectangle.Fill = Brushes.Blue;

Using Hexadecimal Notation:

Note that the first two characters "FF" of the 8-digit
value is the alpha which controls the transparency of
the color. Therefore, to make a completely transparent
color (invisible), use "00" for those digits (e.g. #000000FF).

 <Rectangle Width="50" Height="50" Fill="#FF0000FF" />

Using ARGB Values:

The next example creates a SolidColorBrush and describes its Color using the ARGB values for the color blue.

XAML CODE:

     <Rectangle Width="50" Height="50">
       <Rectangle.Fill>
       <SolidColorBrush>
       <SolidColorBrush.Color>

    <!-- Describes the brush's color using
         RGB values. Each value has a range of 0-255.  
         R is for red, G is for green, and B is for blue.
         A is for alpha which controls transparency of the
         color. Therefore, to make a completely transparent
         color (invisible), use a value of 0 for Alpha. -->
   <Color A="255" R="0" G="0" B="255" />
  </SolidColorBrush.Color>
  </SolidColorBrush>
  </Rectangle.Fill>
  </Rectangle>
answer Nov 12, 2014 by Jdk
...