22 lines
1.3 KiB
XML
22 lines
1.3 KiB
XML
<Window x:Class="_5_17._3创建控件模板.MainWindow"
|
||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||
mc:Ignorable="d"
|
||
Title="MainWindow" Height="450" Width="800">
|
||
<Window.Resources>
|
||
<!-- TargetType="{x:Type Button}" 目标对象是按钮 -->
|
||
<ControlTemplate x:Key="GridControlTemplate" TargetType="{x:Type Button}">
|
||
<Border BorderBrush="Orange" BorderThickness="3" CornerRadius="2" Background="Red"
|
||
TextBlock.Foreground="White">
|
||
<!-- ContentPresenter 在此插入内容;RecognizesAccessKey 不是必须的但是可以使用组合键可以触发 -->
|
||
<!-- Margin="{TemplateBinding Padding}" 如果不加 设置Padding无效 -->
|
||
<ContentPresenter RecognizesAccessKey="True" Margin="{TemplateBinding Padding}" />
|
||
</Border>
|
||
</ControlTemplate>
|
||
</Window.Resources>
|
||
<StackPanel>
|
||
<Button Template="{StaticResource GridControlTemplate}" Margin="15" Padding="15">按钮</Button>
|
||
</StackPanel>
|
||
</Window> |