feat: 5-17.3创建控件模板
This commit is contained in:
parent
cb5f6f0787
commit
fc8f5a9c5e
|
@ -5,7 +5,7 @@
|
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
<ControlTemplate TargetType="{x:Type ResizeGrip}" x:Key="GridControlTemplate">
|
||||
<ControlTemplate TargetType="{x:Type ResizeGrip}">
|
||||
<Grid Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">
|
||||
<Path Margin="0,0,2,2" Data="M9,0L11,0 11,11 0,11 0,9 3,9 3,6 6,6 6,3 9,3z" HorizontalAlignment="Right"
|
||||
VerticalAlignment="Bottom">
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<RootNamespace>_5_17._3创建控件模板</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,9 @@
|
|||
<Application x:Class="_5_17._3创建控件模板.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:_5_17._3创建控件模板"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
|
@ -0,0 +1,12 @@
|
|||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Windows;
|
||||
|
||||
namespace _5_17._3创建控件模板;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
|
@ -0,0 +1,22 @@
|
|||
<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>
|
|
@ -0,0 +1,23 @@
|
|||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace _5_17._3创建控件模板;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "5-17.2理解模板", "5-17.
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "5-17.1理解逻辑树和可视化树", "5-17.1理解逻辑树和可视化树\5-17.1理解逻辑树和可视化树.csproj", "{9A8CFF92-191D-4188-8869-64E526351AA4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "5-17.3创建控件模板", "5-17.3创建控件模板\5-17.3创建控件模板.csproj", "{126C42EA-CC67-4FDA-8839-374F57C667DB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -18,5 +20,9 @@ Global
|
|||
{9A8CFF92-191D-4188-8869-64E526351AA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9A8CFF92-191D-4188-8869-64E526351AA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9A8CFF92-191D-4188-8869-64E526351AA4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{126C42EA-CC67-4FDA-8839-374F57C667DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{126C42EA-CC67-4FDA-8839-374F57C667DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{126C42EA-CC67-4FDA-8839-374F57C667DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{126C42EA-CC67-4FDA-8839-374F57C667DB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
Loading…
Reference in New Issue