perf: beautify the combobox by original codes

dev_without_third_libraries
SONGE9B3\song_pd_win11 2 years ago
parent 2d63969503
commit dfe36cec41

Binary file not shown.

@ -19,14 +19,255 @@
SizeToContent="Height" SizeToContent="Height"
Width="400" Width="400"
Icon="/Images/translate.ico"> Icon="/Images/translate.ico">
<Window.DataContext> <Window.DataContext>
<vm:MainVM /> <vm:MainVM />
</Window.DataContext> </Window.DataContext>
<Window.Resources> <Window.Resources>
<model:VisibilityConverter x:Key="String2VisibilityConverter"/> <model:VisibilityConverter x:Key="String2VisibilityConverter"/>
<ControlTemplate x:Key="ButtonTemplate" TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="4"
MaxHeight="25">
<Image Source="/Images/copy2.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="ButtonTemplateSnakeCopy" TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="4"
MaxHeight="25">
<Image Source="/Images/copy_s.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="ButtonTemplateSmallHumpCopy" TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="4"
MaxHeight="25">
<Image Source="/Images/copy_h.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="ButtonTemplateLargeHumpCopy" TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="4"
MaxHeight="25">
<Image Source="/Images/copy_h2.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>
<!--Combox-->
<Style x:Key="IconStyle" TargetType="TextBlock">
<Setter Property="FontFamily" Value="/STranslate;component/Images/#iconfont"/>
</Style>
<Style TargetType="{x:Type ComboBox}" x:Key="cmbstyle">
<Setter Property="Background" Value="White"/>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<!--ComBoxItem-->
<Style TargetType="ComboBoxItem">
<Setter Property="MinHeight" Value="22"></Setter>
<Setter Property="MinWidth" Value="80"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBoxItem">
<Border Name="Back"
CornerRadius="2"
Background="Transparent"
BorderThickness="0">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,0,0,0"></ContentPresenter>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Back" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsHighlighted" Value="True">
<Setter TargetName="Back" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Border BorderThickness="0" CornerRadius="5" Width="100" Height="30" Background="{TemplateBinding Background}" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" x:Name="grid">
<ToggleButton
Width="{Binding ElementName=grid,Path=ActualWidth}"
Height="{Binding ElementName=grid, Path=ActualHeight}"
Content="{TemplateBinding Text}" VerticalAlignment="Center"
HorizontalAlignment="Left" Margin="5,0,0,0"
BorderThickness="0"
Foreground="{TemplateBinding Foreground}"
Background="{TemplateBinding Background}"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press">
<ToggleButton.Style >
<Style TargetType="ToggleButton">
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border Background="{TemplateBinding Background}" BorderThickness="0" >
<TextBlock Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Content}" Margin="4 0 0 0" HorizontalAlignment="Left" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="White"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Background" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
</ToggleButton>
</Grid>
<Grid Grid.Column="1" >
<ToggleButton IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Foreground="{TemplateBinding Foreground}"
ClickMode="Press">
<ToggleButton.Style>
<Style TargetType="ToggleButton">
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<TextBlock Foreground="{TemplateBinding Foreground}" x:Name="arrow_tb" Text="&#xe61d;" Style="{StaticResource IconStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
</Trigger>
<EventTrigger RoutedEvent="Checked">
<BeginStoryboard>
<Storyboard >
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="arrow_tb" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<EasingDoubleKeyFrame KeyTime="00:00:00.2000000" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Unchecked">
<BeginStoryboard>
<Storyboard >
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="arrow_tb" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
<EasingDoubleKeyFrame KeyTime="00:00:00.2000000" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ToggleButton.Style>
</ToggleButton>
</Grid>
<Popup IsOpen="{TemplateBinding IsDropDownOpen}"
Placement="Bottom" x:Name="Popup"
Focusable="False"
AllowsTransparency="True"
PopupAnimation="Slide">
<Border x:Name="DropDown"
CornerRadius="5"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinWidth="{TemplateBinding ActualWidth}"
SnapsToDevicePixels="True">
<Border.Effect>
<DropShadowEffect Color="Black" BlurRadius="2" ShadowDepth="0" Opacity="0.5"/>
</Border.Effect>
<ScrollViewer Margin="4,6,4,6" MaxHeight="{TemplateBinding MaxDropDownHeight}" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" CanContentScroll="True">
<!-- StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True -->
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" Background="White"/>
</ScrollViewer>
</Border>
</Popup>
</Grid>
<Border.Effect>
<DropShadowEffect ShadowDepth="-1" Opacity="0.3" Color="#FF969696" BlurRadius="2"/>
</Border.Effect>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources> </Window.Resources>
<Border BorderThickness="0"
Background="#fff" <Border Background="#fff"
BorderBrush="#acacac"
BorderThickness="1"
CornerRadius="10"> CornerRadius="10">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
@ -38,14 +279,28 @@
<!--header--> <!--header-->
<Grid x:Name="Header"> <Grid x:Name="Header">
<Button Margin="5,0" <Button Click="Top_Click">
Cursor="Hand" <Button.Template>
BorderBrush="Transparent" <ControlTemplate TargetType="Button">
VerticalAlignment="Top" <Border x:Name="border"
Click="Top_Click" CornerRadius="5"
HorizontalAlignment="Left"> Padding="5"
<Image x:Name="TopImg" HorizontalAlignment="Left"
Height="20"/> 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>
</Grid> </Grid>
@ -56,15 +311,14 @@
<!--输入框--> <!--输入框-->
<Border x:Name="BorderInput" <Border x:Name="BorderInput"
Background="#f6f6f6" Background="#f6f6f6"
BorderBrush="#000" BorderThickness="0"
BorderThickness="1"
CornerRadius="4" CornerRadius="4"
Margin="5"> Margin="5">
<Grid> <Grid>
<TextBox x:Name="TextBoxInput" <TextBox x:Name="TextBoxInput"
Background="Transparent" Background="Transparent"
BorderBrush="{x:Null}" BorderBrush="{x:Null}"
Margin="5,5,5,35" Margin="10,10,5,35"
BorderThickness="0" BorderThickness="0"
FontSize="16" FontSize="16"
MinHeight="70" MinHeight="70"
@ -73,27 +327,21 @@
AcceptsReturn="True" AcceptsReturn="True"
VerticalContentAlignment="Top" VerticalContentAlignment="Top"
HorizontalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden"
Text="{Binding InputTxt,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"> Text="{Binding InputTxt,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<TextBox.InputBindings> <TextBox.InputBindings>
<KeyBinding Command="{Binding TranslateCmd}" Key="Enter" /> <KeyBinding Command="{Binding TranslateCmd}" Key="Enter" />
</TextBox.InputBindings> </TextBox.InputBindings>
</TextBox> </TextBox>
<StackPanel Orientation="Horizontal" <StackPanel Orientation="Horizontal"
Margin="10" Margin="10,5"
VerticalAlignment="Bottom"> VerticalAlignment="Bottom">
<Button Cursor="Hand" <Button Template="{StaticResource ButtonTemplate}"
Visibility="{Binding InputTxt,Converter={StaticResource String2VisibilityConverter}}" Visibility="{Binding InputTxt,Converter={StaticResource String2VisibilityConverter}}"
MaxHeight="22" Command="{Binding CopyInputCmd}"/>
Padding="2" <Border Margin="10,0,0,2"
Background="Transparent"
BorderThickness="0"
Command="{Binding CopyInputCmd}">
<Image Source="/Images/copy2.png"/>
</Button>
<Border Margin="10,0,0,0"
Background="#eaeaea" Background="#eaeaea"
CornerRadius="10" CornerRadius="8"
Visibility="{Binding IdentifyLanguage,Converter={StaticResource String2VisibilityConverter}}" Visibility="{Binding IdentifyLanguage,Converter={StaticResource String2VisibilityConverter}}"
VerticalAlignment="Bottom"> VerticalAlignment="Bottom">
<StackPanel Margin="5,2" <StackPanel Margin="5,2"
@ -118,17 +366,17 @@
Background="Transparent" Background="Transparent"
BorderThickness="0" /> BorderThickness="0" />
<ComboBox x:Name="InCombo" <ComboBox x:Name="InCombo"
Background="#f6f6f6" Style="{StaticResource cmbstyle}"
ItemsSource="{Binding InputCombo}" ItemsSource="{Binding InputCombo}"
SelectedItem="{Binding InputComboSelected}" /> SelectedItem="{Binding InputComboSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
<Separator Margin="20,0"/> <Separator Margin="20,0"/>
<Label Content="目标语言:" <Label Content="目标语言:"
Background="Transparent" Background="Transparent"
BorderThickness="0" /> BorderThickness="0" />
<ComboBox x:Name="OutCombo" <ComboBox x:Name="OutCombo"
Background="#f6f6f6" Style="{StaticResource cmbstyle}"
ItemsSource="{Binding OutputCombo}" ItemsSource="{Binding OutputCombo}"
SelectedItem="{Binding OutputComboSelected}" /> SelectedItem="{Binding OutputComboSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
</StackPanel> </StackPanel>
<!--output--> <!--output-->
@ -138,8 +386,7 @@
<!--输出框--> <!--输出框-->
<Border x:Name="BorderOutput" <Border x:Name="BorderOutput"
Background="#f6f6f6" Background="#f6f6f6"
BorderBrush="#000" BorderThickness="0"
BorderThickness="1"
CornerRadius="4" CornerRadius="4"
Margin="5" Margin="5"
Height="{Binding ElementName=Output, Path=Height}"> Height="{Binding ElementName=Output, Path=Height}">
@ -149,67 +396,35 @@
BorderBrush="{x:Null}" BorderBrush="{x:Null}"
BorderThickness="0" BorderThickness="0"
IsReadOnly="True" IsReadOnly="True"
Margin="5,5,5,30" Margin="10,10,5,35"
MaxHeight="400" MaxHeight="400"
FontSize="16" FontSize="16"
TextWrapping="Wrap" TextWrapping="Wrap"
VerticalContentAlignment="Top" VerticalContentAlignment="Top"
HorizontalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden"
Text="{Binding OutputTxt}"/> Text="{Binding OutputTxt}"/>
<StackPanel Orientation="Horizontal" <StackPanel Orientation="Horizontal"
Margin="10,5" Margin="10,5"
VerticalAlignment="Bottom"> VerticalAlignment="Bottom">
<!--普通复制--> <!--普通复制-->
<Button Cursor="Hand" <Button Template="{StaticResource ButtonTemplate}"
MaxHeight="22"
Padding="2"
Background="Transparent"
BorderThickness="0"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Visibility="{Binding OutputTxt,Converter={StaticResource String2VisibilityConverter}}" Visibility="{Binding OutputTxt,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopyResultCmd}"> Command="{Binding CopyResultCmd}"/>
<Image Source="/Images/copy2.png"/>
</Button>
<!--蛇形复制--> <!--蛇形复制-->
<Button Cursor="Hand" <Button Margin="5,0"
Margin="5,0" Template="{StaticResource ButtonTemplateSnakeCopy}"
MaxHeight="22"
Padding="2"
Background="Transparent"
BorderThickness="0"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Visibility="{Binding SnakeRet,Converter={StaticResource String2VisibilityConverter}}" Visibility="{Binding SnakeRet,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopySnakeResultCmd}"> Command="{Binding CopySnakeResultCmd}"/>
<Image Source="/Images/copy_s.png"/> <!--小驼峰复制-->
</Button> <Button Template="{StaticResource ButtonTemplateSmallHumpCopy}"
<!--驼峰复制-->
<Button Cursor="Hand"
MaxHeight="22"
Padding="2"
Background="Transparent"
BorderThickness="0"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Visibility="{Binding SmallHumpRet,Converter={StaticResource String2VisibilityConverter}}" Visibility="{Binding SmallHumpRet,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopySmallHumpResultCmd}"> Command="{Binding CopySmallHumpResultCmd}"/>
<Image Source="/Images/copy_h.png"/> <!--大驼峰复制-->
</Button> <Button Margin="5,0"
<!--驼峰复制--> Template="{StaticResource ButtonTemplateLargeHumpCopy}"
<Button Cursor="Hand"
Margin="5,0"
MaxHeight="22"
Padding="2"
Background="Transparent"
BorderThickness="0"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Visibility="{Binding LargeHumpRet,Converter={StaticResource String2VisibilityConverter}}" Visibility="{Binding LargeHumpRet,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopyLargeHumpResultCmd}"> Command="{Binding CopyLargeHumpResultCmd}"/>
<Image Source="/Images/copy_h2.png"/>
</Button>
</StackPanel> </StackPanel>
</Grid> </Grid>
</Border> </Border>

@ -88,7 +88,7 @@ namespace STranslate
this.Hide(); this.Hide();
//取消置顶 //取消置顶
this.TopImg.Source = UnLockImgPath; vm.TopImgSource = UnLockImgPath;
} }
//置顶 Ctrl+Shift+T //置顶 Ctrl+Shift+T
if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control) if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control)
@ -159,7 +159,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 (this.TopImg.Source == UnLockImgPath) if (vm.TopImgSource == UnLockImgPath)
{ {
this.Hide(); this.Hide();
} }
@ -244,7 +244,7 @@ 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)
{ {
this.TopImg.Source = TopImg.Source == LockImgPath ? UnLockImgPath : LockImgPath; vm.TopImgSource = vm.TopImgSource == LockImgPath ? UnLockImgPath : LockImgPath;
} }
/// <summary> /// <summary>
/// 退出 /// 退出
@ -259,7 +259,7 @@ namespace STranslate
} }
private void InitView() private void InitView()
{ {
this.TopImg.Source = UnLockImgPath; vm.TopImgSource = UnLockImgPath;
this.Activate(); this.Activate();
this.TextBoxInput.Focus(); this.TextBoxInput.Focus();

@ -125,6 +125,9 @@
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource> </EmbeddedResource>
<Resource Include="Images\iconfont.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>

@ -6,6 +6,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media.Imaging;
namespace STranslate.ViewModel namespace STranslate.ViewModel
{ {
@ -213,6 +214,12 @@ 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