20230724_MBJC_upperpc/Views/SupportModel.xaml.cs
2024-02-27 17:21:02 +08:00

113 lines
4.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace _20230724_MBJC_upperpc.Views
{
/// <summary>
/// SupportModel.xaml 的交互逻辑
/// </summary>
public partial class SupportModel : UserControl
{
//包装器
public float Rotate_X
{
get { return (float)this.GetValue(Rotate_XProperty); }
set { this.SetValue(Rotate_XProperty, value); }
}
public static readonly DependencyProperty Rotate_XProperty = DependencyProperty.Register("Rotate_X", typeof(float), typeof(SupportModel), new PropertyMetadata(default(float), new PropertyChangedCallback(OnPropertyChanged)));
public float Rotate_Y
{
get { return (float)this.GetValue(Rotate_YProperty); }
set { this.SetValue(Rotate_YProperty, value); }
}
public static readonly DependencyProperty Rotate_YProperty = DependencyProperty.Register("Rotate_Y", typeof(float), typeof(SupportModel), new PropertyMetadata(default(float), new PropertyChangedCallback(OnPropertyChanged)));
public float Rotate_Z
{
get { return (float)this.GetValue(Rotate_ZProperty); }
set { this.SetValue(Rotate_ZProperty, value); }
}
public static readonly DependencyProperty Rotate_ZProperty = DependencyProperty.Register("Rotate_Z", typeof(float), typeof(SupportModel), new PropertyMetadata(default(float), new PropertyChangedCallback(OnPropertyChanged)));
/// <summary>
/// 是否可以使用鼠标跟随
/// </summary>
public bool TBDEnable
{
get { return (bool)this.GetValue(TBDEnableProperty); }
set { this.SetValue(TBDEnableProperty, value); }
}
public static readonly DependencyProperty TBDEnableProperty = DependencyProperty.Register("TBDEnable", typeof(bool), typeof(SupportModel), new PropertyMetadata(default(bool), new PropertyChangedCallback(OnPropertyChanged)));
/// <summary>
/// 是否启用线性动画
/// </summary>
public bool AnimationEnable
{
get { return (bool)this.GetValue(AnimationEnableProperty); }
set { this.SetValue(AnimationEnableProperty, value); }
}
public static readonly DependencyProperty AnimationEnableProperty = DependencyProperty.Register("AnimationEnable", typeof(bool), typeof(SupportModel), new PropertyMetadata(default(bool), new PropertyChangedCallback(OnPropertyChanged)));
public static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as SupportModel).Refresh();
}
public SupportModel()
{
InitializeComponent();
}
private void Refresh()
{
if (AnimationEnable)
{
if (this.rotateX.Angle != Rotate_X)
{
DoubleAnimation rotationAnimation = new DoubleAnimation(this.rotateX.Angle, Rotate_X - 90, TimeSpan.FromSeconds(2));
rotateX.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotationAnimation);
}
if (this.rotateY.Angle != Rotate_Y)
{
DoubleAnimation rotationAnimation = new DoubleAnimation(this.rotateY.Angle, Rotate_Y + 90, TimeSpan.FromSeconds(2));
rotateY.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotationAnimation);
}
if (this.rotateZ.Angle != Rotate_Z)
{
DoubleAnimation rotationAnimation = new DoubleAnimation(this.rotateZ.Angle, Rotate_Z, TimeSpan.FromSeconds(2));
rotateZ.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotationAnimation);
}
}
else
{
this.rotateX.Angle = Rotate_X - 90;
this.rotateY.Angle = Rotate_Y + 90;
this.rotateZ.Angle = Rotate_Z;
}
this.TBD.IsEnabled = TBDEnable;
}
}
}