5-WPFTemplates-And-CustomEl.../5-17.3创建控件模板/MainWindow.xaml

22 lines
1.3 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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>