dev_split_view_vm
DESKTOP-3BO4HSG\ksat 2 years ago
parent f3992b2f19
commit 1740c9b6fa

@ -14,7 +14,6 @@
AllowsTransparency="True" AllowsTransparency="True"
ShowInTaskbar="False" ShowInTaskbar="False"
ResizeMode="NoResize" ResizeMode="NoResize"
KeyDown="Window_KeyDown"
Topmost="True" Topmost="True"
Deactivated="Window_Deactivated" Deactivated="Window_Deactivated"
WindowStyle="None" WindowStyle="None"
@ -38,6 +37,17 @@
</ContextMenu> </ContextMenu>
</Window.Resources> </Window.Resources>
<Window.InputBindings>
<KeyBinding Modifiers="Ctrl+Shift"
Key="Q"
Command="{Binding ExitCmd}"/>
<KeyBinding Modifiers="Ctrl+Shift"
Key="T"
Command="{Binding TopmostCmd}"/>
<KeyBinding Key="Esc"
Command="{Binding EscCmd}"/>
</Window.InputBindings>
<Border Style="{DynamicResource BorderMainStyle}"> <Border Style="{DynamicResource BorderMainStyle}">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
@ -58,8 +68,8 @@
<!--header--> <!--header-->
<Grid x:Name="Header"> <Grid x:Name="Header">
<Button x:Name="TopmostBtn" <Button x:Name="TopmostBtn"
Template="{DynamicResource ButtonTemplateUnTopmost}" Command="{Binding TopmostCmd}"
Click="Top_Click"/> Template="{DynamicResource ButtonTemplateUnTopmost}"/>
<Button Width="auto" <Button Width="auto"
Template="{DynamicResource ButtonTemplateTheme}" Template="{DynamicResource ButtonTemplateTheme}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
@ -78,6 +88,7 @@
<!--input--> <!--input-->
<Grid x:Name="Input" <Grid x:Name="Input"
Grid.Row="1" Grid.Row="1"
FocusManager.FocusedElement="{Binding ElementName=TextBoxInput}"
Margin="10,0,10,0"> Margin="10,0,10,0">
<!--输入框--> <!--输入框-->
<Border x:Name="BorderInput" <Border x:Name="BorderInput"

@ -27,53 +27,6 @@ namespace STranslate
//} //}
} }
/// <summary>
/// 移动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}
/// <summary>
/// 软件运行时快捷键
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_KeyDown(object sender, KeyEventArgs e)
{
//最小化 Esc
if (e.Key == Key.Escape)
{
this.Hide();
//取消置顶
if (_IsTopmost)
{
TopmostBtn.SetResourceReference(TemplateProperty, _UnTopmostTemplateName);
_IsTopmost = !_IsTopmost;
}
}
//置顶 Ctrl+Shift+T
if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control)
&& e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Shift)
&& e.Key == Key.T)
{
Top_Click(null, null);
}
//退出 Ctrl+Shift+Q
if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control)
&& e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Shift)
&& e.Key == Key.Q)
{
vm.ExitApp();
}
}
/// <summary> /// <summary>
/// 监听全局快捷键 /// 监听全局快捷键
/// </summary> /// </summary>
@ -103,40 +56,30 @@ namespace STranslate
}); });
} }
/// <summary> /// <summary>
/// 非激活窗口则隐藏起来 /// 移动
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Window_Deactivated(object sender, EventArgs e) private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{ {
if (!_IsTopmost) DragMove();
{
vm.Speech.SpeakAsyncCancelAll();
this.Hide();
}
} }
/// <summary> /// <summary>
/// 是否置顶(不好拆) /// 非激活窗口则隐藏起来
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Top_Click(object sender, RoutedEventArgs e) private void Window_Deactivated(object sender, EventArgs e)
{ {
if (_IsTopmost) if (!vm.IsTopmost)
{
TopmostBtn.SetResourceReference(TemplateProperty, _UnTopmostTemplateName);
}
else
{ {
TopmostBtn.SetResourceReference(TemplateProperty, _TopmostTemplateName); vm.Speech.SpeakAsyncCancelAll();
this.Hide();
} }
_IsTopmost = !_IsTopmost;
} }
private bool _IsTopmost { get; set; }
private readonly string _TopmostTemplateName = "ButtonTemplateTopmost";
private readonly string _UnTopmostTemplateName = "ButtonTemplateUnTopmost";
private void SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) private void SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{ {

@ -62,6 +62,36 @@ namespace STranslate.ViewModel
ExitApp(); ExitApp();
}); });
//置顶
TopmostCmd = new RelayCommand((_) => true, (_) =>
{
if (IsTopmost)
{
(_Mainwin.FindName("TopmostBtn") as System.Windows.Controls.Button)
.SetResourceReference(System.Windows.Controls.Control.TemplateProperty, _UnTopmostTemplateName);
}
else
{
(_Mainwin.FindName("TopmostBtn") as System.Windows.Controls.Button)
.SetResourceReference(System.Windows.Controls.Control.TemplateProperty, _TopmostTemplateName);
}
IsTopmost = !IsTopmost;
});
//ESC
EscCmd = new RelayCommand((_) => true, (_) =>
{
_Mainwin.Hide();
//取消置顶
if (IsTopmost)
{
(_Mainwin.FindName("TopmostBtn") as System.Windows.Controls.Button)
.SetResourceReference(System.Windows.Controls.Control.TemplateProperty, _UnTopmostTemplateName);
IsTopmost = !IsTopmost;
}
});
#endregion #endregion
#region Common #region Common
@ -141,7 +171,7 @@ namespace STranslate.ViewModel
{ {
_Mainwin.Show(); _Mainwin.Show();
_Mainwin.Activate(); _Mainwin.Activate();
//TODO: add textbox focus (_Mainwin.FindName("TextBoxInput") as System.Windows.Controls.TextBox).Focus();
} }
public void InputTranslate() public void InputTranslate()
{ {
@ -153,8 +183,8 @@ namespace STranslate.ViewModel
ClearAll(); ClearAll();
var sentence = GetWordsHelper.Get(); var sentence = GetWordsHelper.Get();
OpenMainWin(); OpenMainWin();
//TODO: add textbox focus (_Mainwin.FindName("TextBoxInput") as System.Windows.Controls.TextBox)
//this.TextBoxInput.Text = sentence.Trim(); .Text = sentence.Trim();
_ = Translate(); _ = Translate();
} }
public void ExitApp() public void ExitApp()
@ -344,6 +374,8 @@ namespace STranslate.ViewModel
public ICommand ShowMainWinCmd { get; private set; } public ICommand ShowMainWinCmd { get; private set; }
public ICommand StartupCmd { get; private set; } public ICommand StartupCmd { get; private set; }
public ICommand ExitCmd { get; private set; } public ICommand ExitCmd { get; private set; }
public ICommand TopmostCmd { get; private set; }
public ICommand EscCmd { get; private set; }
/// <summary> /// <summary>
/// 是否开机自启 /// 是否开机自启
@ -354,6 +386,9 @@ namespace STranslate.ViewModel
public bool IsVisibility { get => _IsVisibility; set => UpdateProperty(ref _IsVisibility, value); } public bool IsVisibility { get => _IsVisibility; set => UpdateProperty(ref _IsVisibility, value); }
private MainWindow _Mainwin; private MainWindow _Mainwin;
public bool IsTopmost { get; set; }
private readonly string _TopmostTemplateName = "ButtonTemplateTopmost";
private readonly string _UnTopmostTemplateName = "ButtonTemplateUnTopmost";
/// <summary> /// <summary>
/// 全局配置文件 /// 全局配置文件

Loading…
Cancel
Save