perf: update change topmost template by theme

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

@ -34,29 +34,9 @@
<!--header-->
<Grid x:Name="Header">
<Button Click="Top_Click">
<Button.Template>
<ControlTemplate TargetType="Button">
<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 x:Name="TopmostBtn"
Template="{DynamicResource ButtonTemplateUnTopmost}"
Click="Top_Click"/>
<Button Template="{DynamicResource ButtonTemplate}"
Width="30"
HorizontalAlignment="Right"

@ -101,7 +101,7 @@ namespace STranslate
this.Hide();
//取消置顶
vm.TopImgSource = _UnTopmost;
TopmostBtn.SetResourceReference(TemplateProperty, _UnTopmostTemplateName);
}
//置顶 Ctrl+Shift+T
if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control)
@ -174,7 +174,7 @@ namespace STranslate
/// <param name="e"></param>
private void Window_Deactivated(object sender, EventArgs e)
{
if (vm.TopImgSource == _UnTopmost)
if (!_IsTopmost)
{
this.Hide();
}
@ -259,7 +259,15 @@ namespace STranslate
/// <param name="e"></param>
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>
/// 退出
@ -274,13 +282,12 @@ namespace STranslate
}
private void InitView()
{
vm.TopImgSource = _UnTopmost;
this.Activate();
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 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"
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">
<Border x:Name="border"
CornerRadius="5"

@ -22,7 +22,11 @@
<Setter Property="Foreground" Value="WhiteSmoke"/>
<Setter Property="BorderBrush" Value="{x:Null}"/>
<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="MinHeight" Value="70"/>
<Setter Property="MaxHeight" Value="200"/>

@ -1,6 +1,45 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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">
<Border x:Name="border"
CornerRadius="5"

@ -21,7 +21,7 @@
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="{x:Null}"/>
<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="MinHeight" Value="70"/>
<Setter Property="MaxHeight" Value="200"/>

@ -214,12 +214,6 @@ namespace STranslate.ViewModel
private string _LargeHumpRet;
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;
public string InputTxt { get => _InputTxt; set => UpdateProperty(ref _InputTxt, value); }

Loading…
Cancel
Save