MyLinearGradientBrush.EndPoint = new Point(1,1) LinearGradientBrush myLinearGradientBrush = Create a diagonal linear gradient with four stops. Rectangle diagonalFillRectangle = new Rectangle() The following example shows the code that creates a linear gradient with four colors. By default, a diagonal gradient is created. The gradient axis is described in the next section. You may also modify the gradient axis, which enables you to create horizontal and vertical gradients and to reverse the gradient direction. You specify the gradient's colors and their location along the gradient axis using GradientStop objects. WPF provides two types of gradient brushes: LinearGradientBrush and RadialGradientBrush.Ī LinearGradientBrush paints an area with a gradient defined along a line, the gradient axis. You can also use them to simulate glass, chrome, water, and other smooth surfaces. You can use them to create impressions of light and shadow, giving your controls a three-dimensional feel. Button myButton = new Button() Ģ55, // Specifies the transparency of the color.įor additional ways to specify color, see the Color reference topic.Ī gradient brush paints an area with multiple colors that blend into each other along an axis. In the following example, a brush's color is described by specifying alpha, red, green, and blue values. Likewise, a red value of 0 indicates that a color has no red in it, while a value of 255 indicates a color has the maximum amount of red possible. For example, an alpha value of 0 indicates that a color is completely transparent, while a value of 255 indicates the color is completely opaque. The typical range for each of these values is 0-255. The static FromArgb enables you to specify the color's alpha, red, green, and blue values. SolidColorBrush mySolidColorBrush = new SolidColorBrush() The following example shows how to set the Color property of a SolidColorBrush using a predefined color. You can use a predefined color from the Colors class or you can create a Color using the static FromArgb method. Button myButton = new Button() Ĭreate a SolidColorBrush and set its Color property using a Color structure. In the following example, the Background of a Button is set to Red. Use one of the predefined brushes provided by the Brushes class. To paint an area with a solid color in code, use one of the following options. The second brush's color is described using hexadecimal notation. The first brush's color is described using a predefined color name. In the following example, the Background properties of two Button elements are set to fully-opaque red. This syntax is more verbose but enables you to specify additional settings, such as the brush's opacity. Use property tag syntax to describe a SolidColorBrush. In the following example, the Background of a Button is set to fully-opaque red using hexadecimal notation. This approach enables you to create colors that are partially transparent. Additionally, the color can be specified as "# aarrggbb" where aa specifies the alpha value, or transparency, of the color. The format for specifying a color from the 32-bit palette is " #rrggbb", where rr is a two digit hexadecimal number specifying the relative amount of red, gg specifies the amount of green, and bb specifies the amount of blue. Ĭhoose a color from the 32-bit color palette by specifying the amounts of red, green, and blue to combine into a single solid color. For a list of other predefined solid color brushes, see the static properties of the Brushes class. For example, you can set a button's Background to "Red" or "MediumBlue". Select a predefined solid color brush by name. To paint an area with a solid color in XAML, use one of the following options. The following sections describe the different ways to paint with a SolidColorBrush. To accomplish this task, Windows Presentation Foundation (WPF) provides the SolidColorBrush class. One of the most common operations in any platform is to paint an area with a solid Color. This topic describes how to use SolidColorBrush, LinearGradientBrush, and RadialGradientBrush objects to paint with solid colors, linear gradients, and radial gradients.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |