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"
Width="400"
Icon="/Images/translate.ico">
<Window.DataContext>
<vm:MainVM />
</Window.DataContext>
<Window.Resources>
<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>
<Border BorderThickness="0"
Background="#fff"
<Border Background="#fff"
BorderBrush="#acacac"
BorderThickness="1"
CornerRadius="10">
<Grid>
<Grid.RowDefinitions>
@ -38,14 +279,28 @@
<!--header-->
<Grid x:Name="Header">
<Button Margin="5,0"
Cursor="Hand"
BorderBrush="Transparent"
VerticalAlignment="Top"
Click="Top_Click"
HorizontalAlignment="Left">
<Image x:Name="TopImg"
Height="20"/>
<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>
</Grid>
@ -56,15 +311,14 @@
<!--输入框-->
<Border x:Name="BorderInput"
Background="#f6f6f6"
BorderBrush="#000"
BorderThickness="1"
BorderThickness="0"
CornerRadius="4"
Margin="5">
<Grid>
<TextBox x:Name="TextBoxInput"
Background="Transparent"
BorderBrush="{x:Null}"
Margin="5,5,5,35"
Margin="10,10,5,35"
BorderThickness="0"
FontSize="16"
MinHeight="70"
@ -73,27 +327,21 @@
AcceptsReturn="True"
VerticalContentAlignment="Top"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Hidden"
Text="{Binding InputTxt,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<TextBox.InputBindings>
<KeyBinding Command="{Binding TranslateCmd}" Key="Enter" />
</TextBox.InputBindings>
</TextBox>
<StackPanel Orientation="Horizontal"
Margin="10"
Margin="10,5"
VerticalAlignment="Bottom">
<Button Cursor="Hand"
<Button Template="{StaticResource ButtonTemplate}"
Visibility="{Binding InputTxt,Converter={StaticResource String2VisibilityConverter}}"
MaxHeight="22"
Padding="2"
Background="Transparent"
BorderThickness="0"
Command="{Binding CopyInputCmd}">
<Image Source="/Images/copy2.png"/>
</Button>
<Border Margin="10,0,0,0"
Command="{Binding CopyInputCmd}"/>
<Border Margin="10,0,0,2"
Background="#eaeaea"
CornerRadius="10"
CornerRadius="8"
Visibility="{Binding IdentifyLanguage,Converter={StaticResource String2VisibilityConverter}}"
VerticalAlignment="Bottom">
<StackPanel Margin="5,2"
@ -118,17 +366,17 @@
Background="Transparent"
BorderThickness="0" />
<ComboBox x:Name="InCombo"
Background="#f6f6f6"
Style="{StaticResource cmbstyle}"
ItemsSource="{Binding InputCombo}"
SelectedItem="{Binding InputComboSelected}" />
SelectedItem="{Binding InputComboSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
<Separator Margin="20,0"/>
<Label Content="目标语言:"
Background="Transparent"
BorderThickness="0" />
<ComboBox x:Name="OutCombo"
Background="#f6f6f6"
Style="{StaticResource cmbstyle}"
ItemsSource="{Binding OutputCombo}"
SelectedItem="{Binding OutputComboSelected}" />
SelectedItem="{Binding OutputComboSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
<!--output-->
@ -138,8 +386,7 @@
<!--输出框-->
<Border x:Name="BorderOutput"
Background="#f6f6f6"
BorderBrush="#000"
BorderThickness="1"
BorderThickness="0"
CornerRadius="4"
Margin="5"
Height="{Binding ElementName=Output, Path=Height}">
@ -149,67 +396,35 @@
BorderBrush="{x:Null}"
BorderThickness="0"
IsReadOnly="True"
Margin="5,5,5,30"
Margin="10,10,5,35"
MaxHeight="400"
FontSize="16"
TextWrapping="Wrap"
VerticalContentAlignment="Top"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Hidden"
Text="{Binding OutputTxt}"/>
<StackPanel Orientation="Horizontal"
Margin="10,5"
VerticalAlignment="Bottom">
<!--普通复制-->
<Button Cursor="Hand"
MaxHeight="22"
Padding="2"
Background="Transparent"
BorderThickness="0"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
<Button Template="{StaticResource ButtonTemplate}"
Visibility="{Binding OutputTxt,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopyResultCmd}">
<Image Source="/Images/copy2.png"/>
</Button>
Command="{Binding CopyResultCmd}"/>
<!--蛇形复制-->
<Button Cursor="Hand"
Margin="5,0"
MaxHeight="22"
Padding="2"
Background="Transparent"
BorderThickness="0"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
<Button Margin="5,0"
Template="{StaticResource ButtonTemplateSnakeCopy}"
Visibility="{Binding SnakeRet,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopySnakeResultCmd}">
<Image Source="/Images/copy_s.png"/>
</Button>
<!--驼峰复制-->
<Button Cursor="Hand"
MaxHeight="22"
Padding="2"
Background="Transparent"
BorderThickness="0"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Command="{Binding CopySnakeResultCmd}"/>
<!--小驼峰复制-->
<Button Template="{StaticResource ButtonTemplateSmallHumpCopy}"
Visibility="{Binding SmallHumpRet,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopySmallHumpResultCmd}">
<Image Source="/Images/copy_h.png"/>
</Button>
<!--驼峰复制-->
<Button Cursor="Hand"
Margin="5,0"
MaxHeight="22"
Padding="2"
Background="Transparent"
BorderThickness="0"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Command="{Binding CopySmallHumpResultCmd}"/>
<!--大驼峰复制-->
<Button Margin="5,0"
Template="{StaticResource ButtonTemplateLargeHumpCopy}"
Visibility="{Binding LargeHumpRet,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopyLargeHumpResultCmd}">
<Image Source="/Images/copy_h2.png"/>
</Button>
Command="{Binding CopyLargeHumpResultCmd}"/>
</StackPanel>
</Grid>
</Border>

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

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

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