WPF brush learning 1

In these two blog posts, wpf brushes are mentioned,

https://blog.csdn.net/bcbobo21cn/article/details/109699703
https://blog.csdn.net/bcbobo21cn/article/details/107133703

Let's learn about brushes separately;

Wpf has five brushes, and you can also customize the brush. The base class of the brush is Brush;

 

Take a look at the solid color brush; you can set the color and transparency, as shown below;

The above is to set the brush in the Fill property of the Rectangle, see if you can directly set the brush for the Grid;

 

    No, the error is as shown above;

If you set the brush in the Background property of the Grid, you can;

 

    This is the xaml syntax; setting the brush in the Rectangle.Fill property is equal to writing xx.a certain property = xxxbrush; the brush cannot be directly assigned to the Grid, but can be assigned to the Background property of the Grid;

Let's take a look at the linear linear gradient brush again;

 

 Specify the coordinates of the start and end points, the color of the start and end of the gradient, and other attributes;

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    
  <Grid Width="200" Height="200">
    <Grid.Background>
      <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
        <GradientStop Color="Blue" Offset="0"></GradientStop>
        <GradientStop Color="Red" Offset="1"></GradientStop>
      </LinearGradientBrush>
    </Grid.Background>
  </Grid>

</Page>

Guess you like

Origin blog.csdn.net/bcbobo21cn/article/details/132087687