1. 动画效果
1.1 淡入淡出效果
xml
<Window x:Class="WpfApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Click me">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
From="0" To="1" Duration="0:0:2"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
</Window>
1.2 缩放效果
xml
<Window x:Class="WpfApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Click me">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX"
From="0" To="1" Duration="0:0:2"/>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY"
From="0" To="1" Duration="0:0:2"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
<Button.RenderTransform>
<ScaleTransform />
</Button.RenderTransform>
</Button>
</Grid>
</Window>
2. 阴影效果
xml
<Window x:Class="WpfApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Click me" Width="100" Height="50">
<Button.Effect>
<DropShadowEffect BlurRadius="10" Direction="330" ShadowDepth="5" Color="Gray"/>
</Button.Effect>
</Button>
</Grid>
</Window>
3. 模糊效果
3.1 Windows 10 模糊效果
csharp
public static void EnableBlur(Window window)
{
var helper = new WindowInteropHelper(window);
var accent = new AccentPolicy
{
AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND,
AccentFlags = AccentFlags.DrawLeftBorder | AccentFlags.DrawTopBorder | AccentFlags.DrawRightBorder | AccentFlags.DrawBottomBorder,
GradientColor = 0x00FFFFFF
};
AccentPolicyCallback.SetWindowCompositionAttribute(helper.Handle, ref accent);
}
3.2 Windows 11 模糊效果
csharp
public static void EnableMica(Window window)
{
var helper = new WindowInteropHelper(window);
varmica = MicaController.GetMica();
mica?.SetMica(window);
}
4. 亚克力效果
xml
<Window x:Class="WpfApp.MainWindow"
xmlns:xf="clr-namespace:XamlFlair;assembly=XamlFlair.WPF"
Title="MainWindow" Height="350" Width="525">
<Grid xf:Animations.Primary="{StaticResource FadeIn}" />
</Window>
结论
往期精品推荐: