dev_split_view_vm
DESKTOP-3BO4HSG\ksat 2 years ago
parent 980d3e36b8
commit b8c28da3d6

@ -20,10 +20,7 @@
SizeToContent="Height" SizeToContent="Height"
Width="400" Width="400"
Icon="/Images/translate.ico"> Icon="/Images/translate.ico">
<Window.DataContext>
<vm:MainVM />
</Window.DataContext>
<Window.Resources> <Window.Resources>
<ContextMenu x:Key="TrayMenu"> <ContextMenu x:Key="TrayMenu">
<MenuItem Header="输入翻译" <MenuItem Header="输入翻译"

@ -18,6 +18,7 @@ namespace STranslate
{ {
InitializeComponent(); InitializeComponent();
DataContext = new MainVM(this);
vm = (MainVM)DataContext; vm = (MainVM)DataContext;
InitView(); InitView();
@ -247,7 +248,7 @@ namespace STranslate
} }
/// <summary> /// <summary>
/// 是否置顶 /// 是否置顶(不好拆)
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>

@ -17,9 +17,12 @@ namespace STranslate.ViewModel
{ {
public class MainVM : BaseVM, IDisposable public class MainVM : BaseVM, IDisposable
{ {
private MainWindow mainwin;
public MainVM() public MainVM(Window win)
{ {
mainwin = (MainWindow)win;
OpenMainWin();
if (!ReadConfig()) if (!ReadConfig())
{ {
Task.Delay(3000); Task.Delay(3000);
@ -35,20 +38,14 @@ namespace STranslate.ViewModel
//输入翻译 //输入翻译
InputTranslateCmd = new RelayCommand((_) => true, (_) => InputTranslateCmd = new RelayCommand((_) => true, (_) =>
{ {
InputTxt = string.Empty; ClearAll();
OutputTxt = string.Empty; OpenMainWin();
SnakeRet = string.Empty;
SmallHumpRet = string.Empty;
LargeHumpRet = string.Empty;
IdentifyLanguage = string.Empty;
//view操作
}); });
//显示主界面 //显示主界面
ShowMainWinCmd = new RelayCommand((_) => true, (_) => ShowMainWinCmd = new RelayCommand((_) => true, (_) =>
{ {
//view操作 OpenMainWin();
}); });
//开机自启 //开机自启
StartupCmd = new RelayCommand((_) => true, (_) => StartupCmd = new RelayCommand((_) => true, (_) =>
@ -68,6 +65,7 @@ namespace STranslate.ViewModel
#endregion #endregion
#region Common
//source speak //source speak
SourceSpeakCmd = new RelayCommand((_) => true, (_) => SourceSpeakCmd = new RelayCommand((_) => true, (_) =>
{ {
@ -120,9 +118,32 @@ namespace STranslate.ViewModel
{ {
await Translate(); await Translate();
}); });
#endregion
} }
#region handle #region handle
/// <summary>
/// 清空所有
/// </summary>
private void ClearAll()
{
InputTxt = string.Empty;
OutputTxt = string.Empty;
SnakeRet = string.Empty;
SmallHumpRet = string.Empty;
LargeHumpRet = string.Empty;
IdentifyLanguage = string.Empty;
}
/// <summary>
/// 打开主窗口
/// </summary>
private void OpenMainWin()
{
mainwin.Show();
mainwin.Activate();
//TODO: add textbox focus
}
/// <summary> /// <summary>
/// 初始化配置文件 /// 初始化配置文件

Loading…
Cancel
Save