feat: 5-17.4改变属性触发器2

This commit is contained in:
Bunny 2025-01-23 23:12:30 +08:00
parent 02b17c41a0
commit 7cd99dd0c9
7 changed files with 119 additions and 0 deletions

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>_5_17._4改变属性触发器2</RootNamespace>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,9 @@
<Application x:Class="_5_17._4改变属性触发器2.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._4改变属性触发器2"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View File

@ -0,0 +1,12 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace _5_17._4改变属性触发器2;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

View File

@ -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)
)]

View File

@ -0,0 +1,47 @@
<Window x:Class="_5_17._4改变属性触发器2.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>
<ControlTemplate x:Key="ButtonControlTemplate" TargetType="{x:Type Button}">
<Border Name="Border" BorderBrush="Orange" BorderThickness="3" CornerRadius="2" Background="Red"
TextBlock.Foreground="White">
<Grid>
<!-- 获取焦点时周围自定义的边框 -->
<Rectangle Name="FocusCue" Visibility="Hidden" Stroke="Black" StrokeThickness="1"
StrokeDashArray="1 2" SnapsToDevicePixels="True" />
<ContentPresenter RecognizesAccessKey="True" Margin="{TemplateBinding Padding}" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="Background" Value="DarkRed" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Border" Property="Background" Value="Indigo" />
<Setter TargetName="Border" Property="BorderBrush" Value="DarkKhaki" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Border" Property="TextBlock.Background" Value="Gray" />
<Setter TargetName="Border" Property="Background" Value="MistyRose" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="True">
<Setter TargetName="FocusCue" Property="Visibility" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Window.Resources>
<StackPanel>
<Button Template="{StaticResource ButtonControlTemplate}" Margin="10" Padding="15 5">按钮</Button>
<Button Template="{StaticResource ButtonControlTemplate}" Margin="10" Padding="15 5" IsEnabled="False">禁用按钮</Button>
<Button Template="{StaticResource ButtonControlTemplate}" Margin="10" Padding="15 5">按钮</Button>
<Button Template="{StaticResource ButtonControlTemplate}" Margin="10" Padding="15 5">按钮</Button>
</StackPanel>
</Window>

View File

@ -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._4改变属性触发器2;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}

View File

@ -8,6 +8,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "5-17.3创建控件模板",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "5-17.4改变属性触发器", "5-17.4改变属性触发器\5-17.4改变属性触发器.csproj", "{A9E35059-C6E4-4539-B78C-03DD9737D1E3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "5-17.4改变属性触发器2", "5-17.4改变属性触发器2\5-17.4改变属性触发器2.csproj", "{9D6F1664-2363-4674-A3C7-195A16C337E3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -30,5 +32,9 @@ Global
{A9E35059-C6E4-4539-B78C-03DD9737D1E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9E35059-C6E4-4539-B78C-03DD9737D1E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9E35059-C6E4-4539-B78C-03DD9737D1E3}.Release|Any CPU.Build.0 = Release|Any CPU
{9D6F1664-2363-4674-A3C7-195A16C337E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D6F1664-2363-4674-A3C7-195A16C337E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D6F1664-2363-4674-A3C7-195A16C337E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D6F1664-2363-4674-A3C7-195A16C337E3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal