1. 程式人生 > >WPF 為邊框設定樣式

WPF 為邊框設定樣式

<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