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

@ -14,7 +14,6 @@
AllowsTransparency="True"
ShowInTaskbar="False"
ResizeMode="NoResize"
KeyDown="Window_KeyDown"
Topmost="True"
Deactivated="Window_Deactivated"
WindowStyle="None"
@ -38,6 +37,17 @@
</ContextMenu>
</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}">
<Grid>
<Grid.RowDefinitions>
@ -58,8 +68,8 @@
<!--header-->
<Grid x:Name="Header">
<Button x:Name="TopmostBtn"
Template="{DynamicResource ButtonTemplateUnTopmost}"
Click="Top_Click"/>
Command="{Binding TopmostCmd}"
Template="{DynamicResource ButtonTemplateUnTopmost}"/>
<Button Width="auto"
Template="{DynamicResource ButtonTemplateTheme}"
HorizontalAlignment="Right"
@ -78,6 +88,7 @@
<!--input-->
<Grid x:Name="Input"
Grid.Row="1"
FocusManager.FocusedElement="{Binding ElementName=TextBoxInput}"
Margin="10,0,10,0">
<!--输入框-->
<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>
@ -103,40 +56,30 @@ namespace STranslate
});
}
/// <summary>
/// 非激活窗口则隐藏起来
/// 移动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_Deactivated(object sender, EventArgs e)
{
if (!_IsTopmost)
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
vm.Speech.SpeakAsyncCancelAll();
this.Hide();
}
DragMove();
}
/// <summary>
/// 是否置顶(不好拆)
/// 非激活窗口则隐藏起来
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Top_Click(object sender, RoutedEventArgs e)
{
if (_IsTopmost)
private void Window_Deactivated(object sender, EventArgs e)
{
TopmostBtn.SetResourceReference(TemplateProperty, _UnTopmostTemplateName);
}
else
if (!vm.IsTopmost)
{
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)
{

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

Loading…
Cancel
Save