mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-18 02:10:21 +08:00
chore: 添加渐变附加属性
This commit is contained in:
92
src/MaaWpfGui/Extensions/UIBehaviors/FadeBehavior.cs
Normal file
92
src/MaaWpfGui/Extensions/UIBehaviors/FadeBehavior.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
// <copyright file="FadeBehavior.cs" company="MaaAssistantArknights">
|
||||
// MaaWpfGui - A part of the MaaCoreArknights project
|
||||
// Copyright (C) 2021 MistEO and Contributors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License v3.0 only as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
// </copyright>
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Animation;
|
||||
|
||||
namespace MaaWpfGui.Extensions.UIBehaviors;
|
||||
|
||||
public static class FadeBehavior
|
||||
{
|
||||
#region IsActive 属性
|
||||
|
||||
public static readonly DependencyProperty IsActiveProperty =
|
||||
DependencyProperty.RegisterAttached("IsActive", typeof(bool), typeof(FadeBehavior),
|
||||
new(false, OnIsActiveChanged));
|
||||
|
||||
public static bool GetIsActive(DependencyObject obj) => (bool)obj.GetValue(IsActiveProperty);
|
||||
|
||||
public static void SetIsActive(DependencyObject obj, bool value) => obj.SetValue(IsActiveProperty, value);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Duration 属性(新增)
|
||||
|
||||
public static readonly DependencyProperty DurationProperty =
|
||||
DependencyProperty.RegisterAttached("Duration", typeof(TimeSpan), typeof(FadeBehavior),
|
||||
new(TimeSpan.FromSeconds(0.3)));
|
||||
|
||||
public static TimeSpan GetDuration(DependencyObject obj) => (TimeSpan)obj.GetValue(DurationProperty);
|
||||
|
||||
public static void SetDuration(DependencyObject obj, TimeSpan value) => obj.SetValue(DurationProperty, value);
|
||||
|
||||
#endregion
|
||||
|
||||
private static void OnIsActiveChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is not FrameworkElement element)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取动画持续时间(使用附加属性或默认值)
|
||||
var duration = GetDuration(d);
|
||||
|
||||
var storyboard = new Storyboard();
|
||||
var animation = new DoubleAnimation
|
||||
{
|
||||
Duration = new(duration),
|
||||
FillBehavior = FillBehavior.HoldEnd,
|
||||
};
|
||||
|
||||
if ((bool)e.NewValue)
|
||||
{
|
||||
// 显示动画
|
||||
animation.From = 0;
|
||||
animation.To = 1;
|
||||
element.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 隐藏动画
|
||||
animation.From = 1;
|
||||
animation.To = 0;
|
||||
animation.Completed += (s, _) =>
|
||||
{
|
||||
// 动画完成后才真正隐藏元素
|
||||
if (element.Opacity == 0) // 确保没有其他动画改变透明度
|
||||
{
|
||||
element.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Storyboard.SetTarget(animation, element);
|
||||
Storyboard.SetTargetProperty(animation, new PropertyPath(UIElement.OpacityProperty));
|
||||
storyboard.Children.Add(animation);
|
||||
storyboard.Begin();
|
||||
}
|
||||
}
|
||||
@@ -682,6 +682,7 @@ The video aspect ratio needs to be 16:9 without interference factors such as bla
|
||||
<!-- !Gacha Recognition -->
|
||||
<!-- Peep -->
|
||||
<system:String x:Key="Peep">Peep</system:String>
|
||||
<system:String x:Key="PeepTip">See the world through Pallas?</system:String>
|
||||
<system:String x:Key="PeepTargetFps">Target Frame Rate</system:String>
|
||||
<!-- !Peep -->
|
||||
<!-- 小游戏 -->
|
||||
|
||||
@@ -684,6 +684,7 @@ C:\\leidian\\LDPlayer9
|
||||
<!-- !Gacha Recognition -->
|
||||
<!-- Peep -->
|
||||
<system:String x:Key="Peep">Peep</system:String>
|
||||
<system:String x:Key="PeepTip">パラスの目に映る世界を見てみませんか?</system:String>
|
||||
<system:String x:Key="PeepTargetFps">目標フレームレート</system:String>
|
||||
<!-- !Peep -->
|
||||
<!-- 小游戏 -->
|
||||
|
||||
@@ -685,6 +685,7 @@ C:\\leidian\\LDPlayer9
|
||||
<!-- !헤드헌팅 -->
|
||||
<!-- Peep -->
|
||||
<system:String x:Key="Peep">Peep</system:String>
|
||||
<system:String x:Key="PeepTip">팔라스의 눈에 비친 세상을 보시겠어요?</system:String>
|
||||
<system:String x:Key="PeepTargetFps">목표 프레임 속도</system:String>
|
||||
<!-- !Peep -->
|
||||
<!-- 小游戏 -->
|
||||
|
||||
@@ -685,6 +685,7 @@ C:\\leidian\\LDPlayer9。\n
|
||||
<!-- !牛牛抽卡 -->
|
||||
<!-- 牛牛监控 -->
|
||||
<system:String x:Key="Peep">牛牛监控</system:String>
|
||||
<system:String x:Key="PeepTip">看看牛牛眼中的世界?</system:String>
|
||||
<system:String x:Key="PeepTargetFps">目标帧率</system:String>
|
||||
<!-- !牛牛监控 -->
|
||||
<!-- 小游戏 -->
|
||||
|
||||
@@ -684,6 +684,7 @@ C:\\leidian\\LDPlayer9。\n
|
||||
<!-- !Gacha Recognition -->
|
||||
<!-- 牛牛監控 -->
|
||||
<system:String x:Key="Peep">牛牛監控</system:String>
|
||||
<system:String x:Key="PeepTip">看看牛牛眼中的世界?</system:String>
|
||||
<system:String x:Key="PeepTargetFps">目標幀率</system:String>
|
||||
<!-- !牛牛監控 -->
|
||||
<!-- 小游戏 -->
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:ui="clr-namespace:MaaWpfGui.ViewModels.UI"
|
||||
xmlns:uiBehaviors="clr-namespace:MaaWpfGui.Extensions.UIBehaviors"
|
||||
d:DataContext="{d:DesignInstance {x:Type ui:RecognizerViewModel}}"
|
||||
d:DesignHeight="600"
|
||||
d:DesignWidth="800"
|
||||
@@ -416,7 +417,9 @@
|
||||
Margin="10"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Source="{Binding PeepImage}" />
|
||||
uiBehaviors:FadeBehavior.IsActive="{c:Binding Peeping}"
|
||||
Source="{Binding PeepImage}"
|
||||
Visibility="Collapsed" />
|
||||
<Canvas Visibility="{c:Binding !Idle}">
|
||||
<Viewbox Canvas.Left="15" Canvas.Top="15">
|
||||
<Border
|
||||
@@ -549,16 +552,26 @@
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="100" />
|
||||
</Grid.RowDefinitions>
|
||||
<controls:TextBlock
|
||||
Grid.Row="0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
uiBehaviors:FadeBehavior.IsActive="{c:Binding !Peeping}"
|
||||
FontSize="24"
|
||||
Text="{DynamicResource PeepTip}"
|
||||
Visibility="Visible" />
|
||||
<Grid
|
||||
Grid.Row="0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
VerticalAlignment="Center"
|
||||
uiBehaviors:FadeBehavior.IsActive="{c:Binding Peeping}"
|
||||
Visibility="Collapsed">
|
||||
<Image
|
||||
Margin="10"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Source="{Binding PeepImage}" />
|
||||
<Canvas Visibility="{c:Binding !Idle}">
|
||||
<Canvas>
|
||||
<Viewbox Canvas.Left="15" Canvas.Top="15">
|
||||
<Border
|
||||
Padding="4,2"
|
||||
@@ -623,7 +636,7 @@
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Command="{s:Action StartMiniGame}"
|
||||
Content="{c:Binding 'Idle ? "Link Start!" : "Stop!"'}"/>
|
||||
Content="{c:Binding 'Idle ? "Link Start!" : "Stop!"'}" />
|
||||
</Grid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
|
||||
Reference in New Issue
Block a user