fix: fix not clear texts while hide

master
ZGGSONG 2 years ago
parent bc40050c9f
commit d94b20f39b

@ -20,9 +20,6 @@
Height="450" Height="450"
Width="400" Width="400"
Icon="/Images/translate.ico"> Icon="/Images/translate.ico">
<Window.DataContext>
<vm:MainVM/>
</Window.DataContext>
<Border BorderThickness="0" <Border BorderThickness="0"
Background="#fff" Background="#fff"
CornerRadius="10"> CornerRadius="10">

@ -1,4 +1,5 @@
using STranslate.Utils; using STranslate.Utils;
using STranslate.ViewModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -58,6 +59,7 @@ namespace STranslate
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
this.DataContext = MainVM.Instance;
} }
/// <summary> /// <summary>
@ -81,8 +83,8 @@ namespace STranslate
if (e.Key == Key.Escape) if (e.Key == Key.Escape)
{ {
this.Hide(); this.Hide();
this.TextBoxInput.Text = string.Empty; MainVM.Instance.InputTxt = string.Empty;
this.TextBoxOutput.Text = string.Empty; MainVM.Instance.OutputTxt = string.Empty;
} }
//退出 Ctrl+Q //退出 Ctrl+Q
if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control) && e.Key == Key.Q) if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control) && e.Key == Key.Q)
@ -138,9 +140,9 @@ namespace STranslate
/// <param name="e"></param> /// <param name="e"></param>
private void Window_Deactivated(object sender, EventArgs e) private void Window_Deactivated(object sender, EventArgs e)
{ {
//this.Hide(); this.Hide();
//this.TextBoxInput.Text = string.Empty; MainVM.Instance.InputTxt = string.Empty;
//this.TextBoxOutput.Text = string.Empty; MainVM.Instance.OutputTxt = string.Empty;
} }
} }
} }

@ -94,5 +94,8 @@ namespace STranslate.ViewModel
private string _OutputComboSelected; private string _OutputComboSelected;
public string OutputComboSelected { get => _OutputComboSelected; set => UpdateProperty(ref _OutputComboSelected, value); } public string OutputComboSelected { get => _OutputComboSelected; set => UpdateProperty(ref _OutputComboSelected, value); }
private static readonly MainVM _Instance = new MainVM();
public static MainVM Instance { get => _Instance; }
} }
} }