using HandyControl.Tools.Extension; using HandyControl.Tools; 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.Navigation; using System.Windows.Shapes; using CommunityToolkit.Mvvm.Messaging; using LiveTools.Data; namespace LiveTools.Content { /// /// MainWinContent.xaml 的交互逻辑 /// public partial class MainWinContent { private GridLength _columnDefinitionWidth; public MainWinContent() { InitializeComponent(); WeakReferenceMessenger.Default.Register(this, OnReceive); } private void OnLeftMainContentShiftOut(object sender, RoutedEventArgs e) { ButtonShiftOut.Collapse(); GridSplitter.IsEnabled = false; double targetValue = -ColumnDefinitionLeft.MaxWidth; _columnDefinitionWidth = ColumnDefinitionLeft.Width; DoubleAnimation animation = AnimationHelper.CreateAnimation(targetValue, milliseconds: 100); animation.FillBehavior = FillBehavior.Stop; animation.Completed += OnAnimationCompleted; LeftMainContent.RenderTransform.BeginAnimation(TranslateTransform.XProperty, animation); void OnAnimationCompleted(object? _, EventArgs args) { animation.Completed -= OnAnimationCompleted; LeftMainContent.RenderTransform.SetCurrentValue(TranslateTransform.XProperty, targetValue); Grid.SetColumn(MainContent, 0); Grid.SetColumnSpan(MainContent, 2); ColumnDefinitionLeft.MinWidth = 0; ColumnDefinitionLeft.Width = new GridLength(); ButtonShiftIn.Show(); } } private void OnLeftMainContentShiftIn(object sender, RoutedEventArgs e) { ButtonShiftIn.Collapse(); GridSplitter.IsEnabled = true; double targetValue = ColumnDefinitionLeft.Width.Value; DoubleAnimation animation = AnimationHelper.CreateAnimation(targetValue, milliseconds: 100); animation.FillBehavior = FillBehavior.Stop; animation.Completed += OnAnimationCompleted; LeftMainContent.RenderTransform.BeginAnimation(TranslateTransform.XProperty, animation); void OnAnimationCompleted(object? _, EventArgs args) { animation.Completed -= OnAnimationCompleted; LeftMainContent.RenderTransform.SetCurrentValue(TranslateTransform.XProperty, targetValue); Grid.SetColumn(MainContent, 1); Grid.SetColumnSpan(MainContent, 1); ColumnDefinitionLeft.MinWidth = 240; ColumnDefinitionLeft.Width = _columnDefinitionWidth; ButtonShiftOut.Show(); } } private void Border_Loaded(object sender, RoutedEventArgs e) { } private void OnReceive(object recipient, MsgToken message) { switch (message.ID) { case MsgTokenId.Login: if(Config.IsLogin()==1) { LeftMainContent.IsEnabled = true; LeftMainContent.LblNickName.Text = Config.UserInfo.NickName; LeftMainContent.LblOutDate.Text = Config.UserInfo.OutDateStr; } else { LeftMainContent.IsEnabled = false; } break; } } } }