WPF 为边框设置样式

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/milijiangjun/article/details/82858923
<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  >
  <Style x:Key="RacePitBorderStyle" TargetType="Border">
    <Style.Resources>
      <LinearGradientBrush x:Key="RacePitBackgroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <GradientStop Color="#88000000" Offset="0.1" />
        <GradientStop Color="#CC000000" Offset="0.9" />
      </LinearGradientBrush>
      <LinearGradientBrush x:Key="RacePitBorderBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <GradientStop Color="#18000000" Offset="0.1" />
        <GradientStop Color="#08000000" Offset="0.9" />
      </LinearGradientBrush>
    </Style.Resources>

    <Setter Property="Background" Value="{StaticResource RacePitBackgroundBrush}" />
    <Setter Property="BorderBrush" Value="{StaticResource RacePitBorderBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="CornerRadius" Value="8" />
    <Setter Property="Margin" Value="2,4" />
  </Style>
</ResourceDictionary>

定义相应的样式资源:

RacePitBackgroundBrush

RacePitBorderBrush

类型是边框,设置相应的属性如下:

Background

BorderBrush

BorderThickness

CornerRadius

Margin

猜你喜欢

转载自blog.csdn.net/milijiangjun/article/details/82858923