In this article we will be seeing how to create Silverlight SolidColorBrush using Visual studio 2010.
SolidColorBrush is used to paint an area with a solid color.
Namespace: System.Windows.Media
Assembly: PresentationCore (in PresentationCore.dll)
SolidColorBrush:
It is defined by the following properties.
- Color
- Opacity
- Relative Transform
- Transform
Color:
It is used to specify the color of this SolidColorBrush.
Opacity:
It is used to specify the degree of opacity of a Brush.
Relative Transform:
It is used to specify the transformation that is applied to the brush using relative coordinates.
Transform:
It is used to specify the transformation that is applied to the brush. This transformation is applied after the brush's output has been mapped and positioned.
Steps Involved:
Creating a Silverlight Application:
- Open Visual Studio 2010.
- Go to File => New => Project.
- Select Silverlight from the Installed templates and choose the Silverlight Application template.
- Enter the Name and choose the location.
- Click OK.
- In the New Silverlight Application wizard check the "Host the Silverlight Application in a new Web site".
- Click OK.
Creating the UI:
Open MainPage.xaml file and replace the code with the following.
<UserControl x:Class="SilverlightSolidColorBrush.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Canvas Height="200" Width="200" Background="White">
<Rectangle Height="50" Width="50" Canvas.Left="75" Canvas.Top="75">
<Rectangle.Fill>
<SolidColorBrush>
<SolidColorBrush.Color>
<Color A="255" R="250" G="60" B="90"></Color>
</SolidColorBrush.Color>
</SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
</Canvas>
</UserControl>
Testing the solution:
- Build the solution.
- Hit ctrl+F5.