perf: update change topmost template by theme

dev_deconstruction
DESKTOP-3BO4HSG\ksat 2 years ago
parent bc2b460db2
commit 948876bc1c

@ -34,29 +34,9 @@
<!--header--> <!--header-->
<Grid x:Name="Header"> <Grid x:Name="Header">
<Button Click="Top_Click"> <Button x:Name="TopmostBtn"
<Button.Template> Template="{DynamicResource ButtonTemplateUnTopmost}"
<ControlTemplate TargetType="Button"> Click="Top_Click"/>
<Border x:Name="border"
CornerRadius="5"
Padding="5"
HorizontalAlignment="Left"
Margin="8,5,0,0"
MaxHeight="30">
<Image Height="20"
Source="{Binding TopImgSource}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#dddddd"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
<Button Template="{DynamicResource ButtonTemplate}" <Button Template="{DynamicResource ButtonTemplate}"
Width="30" Width="30"
HorizontalAlignment="Right" HorizontalAlignment="Right"

@ -101,7 +101,7 @@ namespace STranslate
this.Hide(); this.Hide();
//取消置顶 //取消置顶
vm.TopImgSource = _UnTopmost; TopmostBtn.SetResourceReference(TemplateProperty, _UnTopmostTemplateName);
} }
//置顶 Ctrl+Shift+T //置顶 Ctrl+Shift+T
if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control) if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control)
@ -174,7 +174,7 @@ 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)
{ {
if (vm.TopImgSource == _UnTopmost) if (!_IsTopmost)
{ {
this.Hide(); this.Hide();
} }
@ -259,7 +259,15 @@ namespace STranslate
/// <param name="e"></param> /// <param name="e"></param>
private void Top_Click(object sender, RoutedEventArgs e) private void Top_Click(object sender, RoutedEventArgs e)
{ {
vm.TopImgSource = vm.TopImgSource == _Topmost ? _UnTopmost : _Topmost; if (_IsTopmost)
{
TopmostBtn.SetResourceReference(TemplateProperty, _UnTopmostTemplateName);
}
else
{
TopmostBtn.SetResourceReference(TemplateProperty, _TopmostTemplateName);
}
_IsTopmost = !_IsTopmost;
} }
/// <summary> /// <summary>
/// 退出 /// 退出
@ -274,13 +282,12 @@ namespace STranslate
} }
private void InitView() private void InitView()
{ {
vm.TopImgSource = _UnTopmost;
this.Activate(); this.Activate();
this.TextBoxInput.Focus(); this.TextBoxInput.Focus();
} }
private static readonly BitmapImage _Topmost = new BitmapImage(new Uri("pack://application:,,,/STranslate;component/Images/Button_Default/topmost.png"));
private static readonly BitmapImage _UnTopmost = new BitmapImage(new Uri("pack://application:,,,/STranslate;component/Images/Button_Default/untopmost.png"));
private System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon(); private System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon();
private bool _IsTopmost { get; set; }
private readonly string _TopmostTemplateName = "ButtonTemplateTopmost";
private readonly string _UnTopmostTemplateName = "ButtonTemplateUnTopmost";
} }
} }

@ -1,6 +1,45 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTemplate x:Key="ButtonTemplateTopmost"
TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="5"
HorizontalAlignment="Left"
Margin="8,5,0,0"
MaxHeight="30">
<Image Height="20"
Source="pack://application:,,,/STranslate;component/Images/Button_Default/topmost.png"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#47484c"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#35333c"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ButtonTemplateUnTopmost"
TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="5"
HorizontalAlignment="Left"
Margin="8,5,0,0"
MaxHeight="30">
<Image Height="20"
Source="pack://application:,,,/STranslate;component/Images/Button_Default/untopmost.png"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#47484c"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#35333c"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ButtonTemplate" TargetType="Button"> <ControlTemplate x:Key="ButtonTemplate" TargetType="Button">
<Border x:Name="border" <Border x:Name="border"
CornerRadius="5" CornerRadius="5"

@ -22,7 +22,11 @@
<Setter Property="Foreground" Value="WhiteSmoke"/> <Setter Property="Foreground" Value="WhiteSmoke"/>
<Setter Property="BorderBrush" Value="{x:Null}"/> <Setter Property="BorderBrush" Value="{x:Null}"/>
<Setter Property="BorderThickness" Value="0"/> <Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderThickness" Value="0"/> <!--光标颜色-->
<Setter Property="CaretBrush" Value="WhiteSmoke"/>
<!--选区颜色-->
<Setter Property="SelectionBrush" Value="#2d445c"/>
<Setter Property="Margin" Value="10,10,5,35"/>
<Setter Property="FontSize" Value="16"/> <Setter Property="FontSize" Value="16"/>
<Setter Property="MinHeight" Value="70"/> <Setter Property="MinHeight" Value="70"/>
<Setter Property="MaxHeight" Value="200"/> <Setter Property="MaxHeight" Value="200"/>

@ -1,6 +1,45 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTemplate x:Key="ButtonTemplateTopmost"
TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="5"
HorizontalAlignment="Left"
Margin="8,5,0,0"
MaxHeight="30">
<Image Height="20"
Source="pack://application:,,,/STranslate;component/Images/Button_Default/topmost.png"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#dddddd"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ButtonTemplateUnTopmost"
TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="5"
HorizontalAlignment="Left"
Margin="8,5,0,0"
MaxHeight="30">
<Image Height="20"
Source="pack://application:,,,/STranslate;component/Images/Button_Default/untopmost.png"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#dddddd"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ButtonTemplate" TargetType="Button"> <ControlTemplate x:Key="ButtonTemplate" TargetType="Button">
<Border x:Name="border" <Border x:Name="border"
CornerRadius="5" CornerRadius="5"

@ -21,7 +21,7 @@
<Setter Property="Background" Value="Transparent"/> <Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="{x:Null}"/> <Setter Property="BorderBrush" Value="{x:Null}"/>
<Setter Property="BorderThickness" Value="0"/> <Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderThickness" Value="0"/> <Setter Property="Margin" Value="10,10,5,35"/>
<Setter Property="FontSize" Value="16"/> <Setter Property="FontSize" Value="16"/>
<Setter Property="MinHeight" Value="70"/> <Setter Property="MinHeight" Value="70"/>
<Setter Property="MaxHeight" Value="200"/> <Setter Property="MaxHeight" Value="200"/>

@ -214,12 +214,6 @@ namespace STranslate.ViewModel
private string _LargeHumpRet; private string _LargeHumpRet;
public string LargeHumpRet { get => _LargeHumpRet; set => UpdateProperty(ref _LargeHumpRet, value); } public string LargeHumpRet { get => _LargeHumpRet; set => UpdateProperty(ref _LargeHumpRet, value); }
/// <summary>
/// 置顶图标
/// </summary>
private BitmapImage _TopImgSource;
public BitmapImage TopImgSource { get => _TopImgSource; set => UpdateProperty(ref _TopImgSource, value); }
private string _InputTxt; private string _InputTxt;
public string InputTxt { get => _InputTxt; set => UpdateProperty(ref _InputTxt, value); } public string InputTxt { get => _InputTxt; set => UpdateProperty(ref _InputTxt, value); }

Loading…
Cancel
Save