当我们在使用WPF的时候,会发现这是一款非常好用的图形界面处理工具。我们在这里将会为大家详细介绍有关WPF样式继承的实现方法。#t#
WPF样式继承代码示例;
- < Page xmlns="http://schemas.
microsoft.com/winfx/2006/xaml
/presentation" xmlns:x="http://
schemas.microsoft.com/winfx/
2006/xaml"> - < Page.Resources>
- < Style x:Key="BASE">
- < Setter Property="Control.
Margin" Value="6"/> - < Setter Property="Control.
Background"> - < Setter.Value>
- < LinearGradientBrush StartPoint=
"0.5,0" EndPoint="0.5,1"> - < GradientStop Offset="1"
Color="#FF7A0000"/> - < GradientStop Offset="0.5"
Color="#FFFF0000"/> - < GradientStop Offset="0.5"
Color="#FFD40000"/> - < GradientStop Offset="0"
Color="#FFFFC5C5"/> - < /LinearGradientBrush>
- < /Setter.Value>
- < /Setter>
- < /Style>
- < Style BasedOn="{StaticResource BASE}
" TargetType="Button"> - < Setter Property="Foreground"
Value="#FFFFFB92"/> - < Setter Property="Padding"
Value="8,3"/> - < /Style>
- < Style BasedOn="{StaticResource BASE}"
TargetType="TextBox"> - < Setter Property="Foreground"
Value="#FFFFFFFF"/> - < /Style>
- < Style x:Key="NewButton" BasedOn="
{StaticResource {x:Type Button}}"
TargetType="Button"> - < Setter Property="FontWeight"
Value="Bold"/> - < Setter Property="FontSize" Value="22"/>
- < Setter Property="BorderBrush">
- < Setter.Value>
- < LinearGradientBrush StartPoint="0,0"
EndPoint="0,1"> - < GradientStop Offset="0"
Color="#FFFF7300"/> - < GradientStop Offset="1"
Color="#03FF0000"/> - < /LinearGradientBrush>
- < /Setter.Value>
- < /Setter>
- < /Style>
- < /Page.Resources>
- < Grid>
- < DockPanel Width="225" Height="256">
- < Button DockPanel.Dock="Bottom">Button
- < /Button>
- < Button DockPanel.Dock="Bottom"
Style="{StaticResource NewButton}">NewButton - < /Button>
- < TextBox AcceptsReturn="True"
DockPanel.Dock="Top" VerticalScrollBar
Visibility="Visible">TextBox
Test Test Test Test Test - < /TextBox>
- < /DockPanel>
- < /Grid>
- < /Page>
WPF样式继承的相关实现方法就为大家介绍到这里。