diff --git a/STranslate/MainWindow.xaml b/STranslate/MainWindow.xaml index 108ed7d..38ff638 100644 --- a/STranslate/MainWindow.xaml +++ b/STranslate/MainWindow.xaml @@ -20,9 +20,6 @@ Height="450" Width="400" Icon="/Images/translate.ico"> - - - diff --git a/STranslate/MainWindow.xaml.cs b/STranslate/MainWindow.xaml.cs index 3d5ef08..4dce364 100644 --- a/STranslate/MainWindow.xaml.cs +++ b/STranslate/MainWindow.xaml.cs @@ -1,4 +1,5 @@ using STranslate.Utils; +using STranslate.ViewModel; using System; using System.Collections.Generic; using System.Linq; @@ -58,6 +59,7 @@ namespace STranslate public MainWindow() { InitializeComponent(); + this.DataContext = MainVM.Instance; } /// @@ -81,8 +83,8 @@ namespace STranslate if (e.Key == Key.Escape) { this.Hide(); - this.TextBoxInput.Text = string.Empty; - this.TextBoxOutput.Text = string.Empty; + MainVM.Instance.InputTxt = string.Empty; + MainVM.Instance.OutputTxt = string.Empty; } //退出 Ctrl+Q if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control) && e.Key == Key.Q) @@ -138,9 +140,9 @@ namespace STranslate /// private void Window_Deactivated(object sender, EventArgs e) { - //this.Hide(); - //this.TextBoxInput.Text = string.Empty; - //this.TextBoxOutput.Text = string.Empty; + this.Hide(); + MainVM.Instance.InputTxt = string.Empty; + MainVM.Instance.OutputTxt = string.Empty; } } } diff --git a/STranslate/ViewModel/MainVM.cs b/STranslate/ViewModel/MainVM.cs index 7afaef2..290b258 100644 --- a/STranslate/ViewModel/MainVM.cs +++ b/STranslate/ViewModel/MainVM.cs @@ -94,5 +94,8 @@ namespace STranslate.ViewModel private string _OutputComboSelected; public string OutputComboSelected { get => _OutputComboSelected; set => UpdateProperty(ref _OutputComboSelected, value); } + private static readonly MainVM _Instance = new MainVM(); + public static MainVM Instance { get => _Instance; } + } }