feat: 5-17.3.4使用动画的触发器
This commit is contained in:
parent
7cd99dd0c9
commit
bf67dfd5db
|
@ -0,0 +1,12 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<RootNamespace>_5_17._3._4使用动画的触发器</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,12 @@
|
|||
<Application x:Class="_5_17._3._4使用动画的触发器.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="Resource/Button.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
|
@ -0,0 +1,12 @@
|
|||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Windows;
|
||||
|
||||
namespace _5_17._3._4使用动画的触发器;
|
||||
|
||||
/// <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,45 @@
|
|||
<Window x:Class="_5_17._3._4使用动画的触发器.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 BorderBrush="Orange" BorderThickness="3" CornerRadius="2" Background="Red"
|
||||
TextBlock.Foreground="Wheat" Name="Border">
|
||||
<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>
|
||||
<EventTrigger RoutedEvent="MouseEnter">
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color"
|
||||
To="Blue" Duration="0:0:1" AutoReverse="True" RepeatBehavior="Forever" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</EventTrigger>
|
||||
<EventTrigger RoutedEvent="MouseLeave">
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color"
|
||||
Duration="0:0:3" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</EventTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Window.Resources>
|
||||
|
||||
<StackPanel>
|
||||
<Button Template="{StaticResource ButtonControlTemplate}" Margin="10" Padding="15 5">按钮</Button>
|
||||
<Button Template="{StaticResource GradientButtonTemplate}"> 111 </Button>
|
||||
<Button Template="{StaticResource GradientButtonTemplate}" IsEnabled="False"> 111 </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._4使用动画的触发器;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<RadialGradientBrush x:Key="HighlightBackground" RadiusX="1" RadiusY="5">
|
||||
<GradientStop Color="White" Offset="0" />
|
||||
<GradientStop Color="Blue" Offset=".4" />
|
||||
</RadialGradientBrush>
|
||||
|
||||
<RadialGradientBrush x:Key="PressedBackground" RadiusX="1" RadiusY="5" GradientOrigin="0.5,0.3">
|
||||
<GradientStop Color="White" Offset="0" />
|
||||
<GradientStop Color="Blue" Offset="1" />
|
||||
</RadialGradientBrush>
|
||||
|
||||
<SolidColorBrush x:Key="DefaultColorBrush" Color="Blue" />
|
||||
<SolidColorBrush x:Key="DisableColorBrush" Color="Gray" />
|
||||
|
||||
<RadialGradientBrush x:Key="Border" RadiusX="1" RadiusY="5" GradientOrigin="0.5,0.3">
|
||||
<GradientStop Color="White" Offset="0" />
|
||||
<GradientStop Color="Blue" Offset="1" />
|
||||
</RadialGradientBrush>
|
||||
|
||||
<ControlTemplate x:Key="GradientButtonTemplate" TargetType="{x:Type Button}">
|
||||
<Border Name="Border" BorderBrush="{StaticResource Border}" BorderThickness="2" CornerRadius="2"
|
||||
Background="{StaticResource DefaultColorBrush}" TextBlock.Foreground="White">
|
||||
<Grid>
|
||||
<Rectangle Name="FocusCue" Visibility="Hidden" Stroke="Black" StrokeThickness="1"
|
||||
StrokeDashArray=" 1 2" SnapsToDevicePixels="True" />
|
||||
<ContentPresenter Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="Border" Property="Background" Value="{StaticResource HighlightBackground}" />
|
||||
</Trigger>
|
||||
|
||||
<Trigger Property="IsKeyboardFocused" Value="True">
|
||||
<Setter TargetName="FocusCue" Property="Visibility" Value="Visible" />
|
||||
</Trigger>
|
||||
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter TargetName="Border" Property="Background" Value="{StaticResource DisableColorBrush}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</ResourceDictionary>
|
|
@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "5-17.4改变属性触发器
|
|||
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
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "5-17.3.4使用动画的触发器", "5-17.3.4使用动画的触发器\5-17.3.4使用动画的触发器.csproj", "{5B571DC8-785A-4466-BC4A-3EBD293E30B7}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -36,5 +38,9 @@ Global
|
|||
{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
|
||||
{5B571DC8-785A-4466-BC4A-3EBD293E30B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5B571DC8-785A-4466-BC4A-3EBD293E30B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5B571DC8-785A-4466-BC4A-3EBD293E30B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5B571DC8-785A-4466-BC4A-3EBD293E30B7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
Loading…
Reference in New Issue