From da7588273ea1c3c8a8381cd5348340b948a81065 Mon Sep 17 00:00:00 2001 From: liufei Date: Mon, 13 Jun 2022 20:35:48 +0800 Subject: [PATCH] =?UTF-8?q?:adhesive=5Fbandage:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E5=90=8E=E4=BB=8D=E6=9C=89=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E7=AA=97=E5=8F=A3,=20=E4=BC=98=E5=8C=96=E4=B8=BB=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserControls/Config/MotionControl.xaml.cs | 5 +- Control/Windows/IconfontWindow.xaml.cs | 2 +- Control/Windows/SystemItemWindow.xaml.cs | 2 +- Converts/ReverseBoolConvert.cs | 22 +++++ GeekDesk.csproj | 2 + MainWindow.xaml | 14 ++- MainWindow.xaml.cs | 87 +++++++++++++------ Util/MarginHide.cs | 14 ++- Util/RelayCommand.cs | 37 ++++++++ Util/ShowWindowFollowMouse.cs | 7 +- ViewModel/AppConfig.cs | 16 ++++ 11 files changed, 165 insertions(+), 43 deletions(-) create mode 100644 Converts/ReverseBoolConvert.cs create mode 100644 Util/RelayCommand.cs diff --git a/Control/UserControls/Config/MotionControl.xaml.cs b/Control/UserControls/Config/MotionControl.xaml.cs index ce775ac..a3907de 100644 --- a/Control/UserControls/Config/MotionControl.xaml.cs +++ b/Control/UserControls/Config/MotionControl.xaml.cs @@ -310,10 +310,9 @@ namespace GeekDesk.Control.UserControls.Config { if (MainWindow.mainWindow.Visibility == Visibility.Collapsed) { - MainWindow.mainWindow.Visibility = Visibility.Visible; - // 执行一下动画 防止太过突兀 - MainWindow.FadeStoryBoard(0, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Collapsed); + appConfig.IsShow = true; } + appConfig.IsShow = null; } diff --git a/Control/Windows/IconfontWindow.xaml.cs b/Control/Windows/IconfontWindow.xaml.cs index 22000cf..67df36a 100644 --- a/Control/Windows/IconfontWindow.xaml.cs +++ b/Control/Windows/IconfontWindow.xaml.cs @@ -138,7 +138,7 @@ namespace GeekDesk.Control.Windows } window.Show(); Keyboard.Focus(window); - ShowWindowFollowMouse.Show(window, MousePosition.LEFT_CENTER, 0, 0, false); + ShowWindowFollowMouse.Show(window, MousePosition.LEFT_CENTER, 0, 0); } private void CustomButton_Click(object sender, RoutedEventArgs e) diff --git a/Control/Windows/SystemItemWindow.xaml.cs b/Control/Windows/SystemItemWindow.xaml.cs index 0f79d65..ec8b6c1 100644 --- a/Control/Windows/SystemItemWindow.xaml.cs +++ b/Control/Windows/SystemItemWindow.xaml.cs @@ -280,7 +280,7 @@ namespace GeekDesk.Control.Windows } window.Show(); Keyboard.Focus(window); - ShowWindowFollowMouse.Show(window, MousePosition.LEFT_CENTER, 0, 0, false); + ShowWindowFollowMouse.Show(window, MousePosition.LEFT_CENTER, 0, 0); } diff --git a/Converts/ReverseBoolConvert.cs b/Converts/ReverseBoolConvert.cs new file mode 100644 index 0000000..dfb9c6b --- /dev/null +++ b/Converts/ReverseBoolConvert.cs @@ -0,0 +1,22 @@ +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace GeekDesk.Converts +{ + internal class ReverseBoolConvert : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null) return null; + bool val = (bool)value; + return !val; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/GeekDesk.csproj b/GeekDesk.csproj index 6fb53bd..0f743f1 100644 --- a/GeekDesk.csproj +++ b/GeekDesk.csproj @@ -256,6 +256,7 @@ + @@ -285,6 +286,7 @@ + diff --git a/MainWindow.xaml b/MainWindow.xaml index 851bb32..c3db11f 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -19,7 +19,7 @@ AllowsTransparency="True" Background="Transparent" ShowInTaskbar="False" - Opacity="0" + Opacity="1" Deactivated="AppWindow_Deactivated" SizeChanged="Window_SizeChanged" PreviewKeyDown="OnKeyDown" @@ -27,8 +27,7 @@ MouseDown="MainWindow_MouseDown" MouseEnter="MainWindow_MouseEnter" GotFocus="Window_GotFocus" - Loaded="Window_Loaded" - xf:Animations.Primary="{xf:Animate BasedOn={StaticResource FadeInAndGrowHorizontally}, Event=Visibility}" + Loaded="Window_Loaded" > @@ -38,6 +37,7 @@ + @@ -57,6 +57,12 @@ Focusable="True" x:Name="BGBorder" hc:Dialog.Token="MainWindowDialog" + xf:Animations.Primary="{xf:Animate BasedOn={StaticResource FadeInAndGrowHorizontally}, Event=None}" + xf:Animations.PrimaryBinding="{Binding AppConfig.IsShow, Mode=OneWay}" + xf:Animations.Secondary="{xf:Animate BasedOn={StaticResource FadeOut}, Event=None}" + xf:Animations.SecondaryBinding="{Binding AppConfig.IsShow, Mode=OneWay, Converter={StaticResource ReverseBoolConvert}}" + xf:Animations.SecondaryCompletionCommand="{Binding HideCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" + xf:Animations.AllowOpacityReset="False" > + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index f943eaf..4b690e9 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -41,7 +41,6 @@ namespace GeekDesk { //加载数据 LoadData(); - InitializeComponent(); //用于其他类访问 @@ -180,14 +179,7 @@ namespace GeekDesk BGSettingUtil.BGSetting(); if (!appData.AppConfig.StartedShowPanel) { - if (appData.AppConfig.AppAnimation) - { - this.Opacity = 0; - } - else - { - this.Visibility = Visibility.Collapsed; - } + this.Visibility = Visibility.Collapsed; } else { @@ -435,7 +427,15 @@ namespace GeekDesk //} MainWindow.mainWindow.Activate(); - mainWindow.Visibility = Visibility.Visible; + mainWindow.Show(); + //mainWindow.Visibility = Visibility.Visible; + if (appData.AppConfig.AppAnimation) + { + appData.AppConfig.IsShow = true; + } else + { + appData.AppConfig.IsShow = null; + } if (MarginHide.ON_HIDE) { @@ -450,10 +450,12 @@ namespace GeekDesk if (appData.AppConfig.FollowMouse) { - ShowWindowFollowMouse.Show(mainWindow, MousePosition.CENTER, 0, 0, false); + ShowWindowFollowMouse.Show(mainWindow, MousePosition.CENTER, 0, 0); } + + + //FadeStoryBoard(1, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Visible); - FadeStoryBoard(1, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Visible); Keyboard.Focus(mainWindow); if (RunTimeStatus.SHOW_MENU_PASSWORDBOX) { @@ -466,25 +468,35 @@ namespace GeekDesk public static void HideApp() { - if (!MarginHide.IS_HIDE) + if (appData.AppConfig.AppAnimation) { - //关闭锁定 - RunTimeStatus.LOCK_APP_PANEL = false; - if (RunTimeStatus.SEARCH_BOX_SHOW) - { - mainWindow.HidedSearchBox(); - FadeStoryBoard(0, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Collapsed); - } - else - { - FadeStoryBoard(0, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Collapsed); - } + appData.AppConfig.IsShow = false; } else { - ShowApp(); + appData.AppConfig.IsShow = null; + HideAppVis(); } + + } + private static void HideAppVis() + { + //关闭锁定 + RunTimeStatus.LOCK_APP_PANEL = false; + if (RunTimeStatus.SEARCH_BOX_SHOW) + { + mainWindow.HidedSearchBox(); + } + mainWindow.Visibility = Visibility.Collapsed; + //if (!MarginHide.IS_HIDE) + //{ + + //} + //else + //{ + // ShowApp(); + //} } /// @@ -802,5 +814,30 @@ namespace GeekDesk RunTimeStatus.APP_BTN_IS_DOWN = false; }).Start(); } + + + private ICommand _hideCommand; + public ICommand HideCommand + { + get + { + if (_hideCommand == null) + { + _hideCommand = new RelayCommand( + p => + { + return true; + }, + p => + { + HideAppVis(); + }); + } + return _hideCommand; + } + } + + + } } diff --git a/Util/MarginHide.cs b/Util/MarginHide.cs index ca73440..a16bbdd 100644 --- a/Util/MarginHide.cs +++ b/Util/MarginHide.cs @@ -77,8 +77,7 @@ namespace GeekDesk.Util #region 窗体贴边隐藏功能 private static void HideWindow(object o, EventArgs e) { - if (window.Visibility != Visibility.Visible - || RunTimeStatus.MARGIN_HIDE_AND_OTHER_SHOW + if (RunTimeStatus.MARGIN_HIDE_AND_OTHER_SHOW || RunTimeStatus.LOCK_APP_PANEL) return; double screenLeft = SystemParameters.VirtualScreenLeft; @@ -98,7 +97,7 @@ namespace GeekDesk.Util //鼠标不在窗口上 if ((mouseX < windowLeft || mouseX > windowLeft + windowWidth - || mouseY < windowTop || mouseY > windowTop + windowHeight) && !IS_HIDE) + || mouseY < windowTop || mouseY > windowTop + windowHeight) && !IS_HIDE && window.Visibility == Visibility.Visible) { //上方隐藏条件 if (windowTop <= screenTop) @@ -126,8 +125,9 @@ namespace GeekDesk.Util } } else if (mouseX >= windowLeft && mouseX <= windowLeft + windowWidth - && mouseY >= windowTop && mouseY <= windowTop + windowHeight && IS_HIDE) + && mouseY >= windowTop && mouseY <= windowTop + windowHeight && IS_HIDE && window.Visibility != Visibility.Visible) { + window.Visibility = Visibility.Visible; //上方显示 if (windowTop <= screenTop - showMarginWidth) { @@ -189,6 +189,7 @@ namespace GeekDesk.Util double windowTop = window.Top; double windowLeft = window.Left; + window.Visibility = Visibility.Visible; //左侧显示 if (windowLeft <= screenLeft - showMarginWidth) { @@ -286,6 +287,11 @@ namespace GeekDesk.Util window.Top = to - 20; break; } + if (hideType > HideType.RIGHT_SHOW) + { + window.Visibility = Visibility.Collapsed; + } + //double toTemp = to; //double leftT = 0; //double topT = 0; diff --git a/Util/RelayCommand.cs b/Util/RelayCommand.cs new file mode 100644 index 0000000..383b0ae --- /dev/null +++ b/Util/RelayCommand.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace GeekDesk.Util +{ + public class RelayCommand : ICommand + { + private readonly Predicate _canExecute; + private readonly Action _execute; + + public RelayCommand(Predicate canExecute, Action execute) + { + _canExecute = canExecute; + _execute = execute; + } + + public event EventHandler CanExecuteChanged + { + add => CommandManager.RequerySuggested += value; + remove => CommandManager.RequerySuggested -= value; + } + + public bool CanExecute(object parameter) + { + return _canExecute(parameter); + } + + public void Execute(object parameter) + { + _execute(parameter); + } + } +} diff --git a/Util/ShowWindowFollowMouse.cs b/Util/ShowWindowFollowMouse.cs index 211ca4b..b5fb787 100644 --- a/Util/ShowWindowFollowMouse.cs +++ b/Util/ShowWindowFollowMouse.cs @@ -21,7 +21,7 @@ namespace GeekDesk.Util /// /// 随鼠标位置显示面板 /// - public static void Show(Window window, MousePosition position, double widthOffset = 0, double heightOffset = 0, bool visibility = true) + public static void Show(Window window, MousePosition position, double widthOffset = 0, double heightOffset = 0) { //获取鼠标位置 System.Windows.Point p = MouseUtil.GetMousePosition(); @@ -101,11 +101,6 @@ namespace GeekDesk.Util { window.Top = p.Y - afterHeight; } - if (visibility) - { - window.Opacity = 0; - window.Visibility = Visibility.Visible; - } } } diff --git a/ViewModel/AppConfig.cs b/ViewModel/AppConfig.cs index 217b06b..d0a4401 100644 --- a/ViewModel/AppConfig.cs +++ b/ViewModel/AppConfig.cs @@ -99,7 +99,23 @@ namespace GeekDesk.ViewModel private string passwordHint; //密码提示 + private bool? isShow; + + #region GetSet + public bool? IsShow + { + get + { + return isShow; + } + set + { + isShow = value; + OnPropertyChanged("IsShow"); + } + } + public string PasswordHint { get