优化更新代码,添加界面功能并整合

This commit is contained in:
GG Z
2025-02-10 20:53:40 +08:00
parent 83b846f15f
commit 978e03a67f
1389 changed files with 95739 additions and 22200 deletions

View File

@@ -0,0 +1,144 @@
using Microsoft.Win32;
namespace WPFluent.Controls;
public class ChooseBox : TextBox
{
private Button PART_ChooseButton;
static ChooseBox()
{ DefaultStyleKeyProperty.OverrideMetadata(typeof(ChooseBox), new FrameworkPropertyMetadata(typeof(ChooseBox))); }
#region Event Implement Function
private void PART_ChooseButton_Click(object sender, RoutedEventArgs e)
{
switch(ChooseBoxType)
{
case ChooseBoxType.SingleFile:
OpenFileDialog openFileDialog =
new()
{
Multiselect = false,
//"文本文件|*.*|C#文件|*.cs|所有文件|*.*"
Filter = Filter
};
if(openFileDialog.ShowDialog() == true)
this.Text = openFileDialog.FileName;
break;
case ChooseBoxType.MultiFile:
break;
case ChooseBoxType.Folder:
var folderDialog = new VistaFolderBrowserDialog();
if(folderDialog.ShowDialog() == true)
this.Text = folderDialog.SelectedPath;
break;
case ChooseBoxType.SaveFile:
var fileDialog = new SaveFileDialog
{
Filter = Filter, //设置文件类型
FileName = DefaultFileName, //设置默认文件名
DefaultExt = DefaultExt, //设置默认格式(可以不设)
AddExtension = true //设置自动在文件名中添加扩展名
};
if(fileDialog.ShowDialog() == true)
this.Text = fileDialog.FileName;
break;
}
}
#endregion
#region Override
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
PART_ChooseButton = this.GetTemplateChild("PART_ChooseButton") as Button;
if(PART_ChooseButton != null)
{
PART_ChooseButton.Click += PART_ChooseButton_Click;
}
}
#endregion
#region ChooseButtonStyle
/// <summary>
/// 获取或者设置选择按钮的样式
/// </summary>
public Style ChooseButtonStyle
{
get { return (Style)GetValue(ChooseButtonStyleProperty); }
set { SetValue(ChooseButtonStyleProperty, value); }
}
public static readonly DependencyProperty ChooseButtonStyleProperty = DependencyProperty.Register(
nameof(ChooseButtonStyle),
typeof(Style),
typeof(ChooseBox));
#endregion
#region ChooseBoxType
public ChooseBoxType ChooseBoxType
{
get { return (ChooseBoxType)GetValue(ChooseBoxTypeProperty); }
set { SetValue(ChooseBoxTypeProperty, value); }
}
public static readonly DependencyProperty ChooseBoxTypeProperty = DependencyProperty.Register(
nameof(ChooseBoxType),
typeof(ChooseBoxType),
typeof(ChooseBox),
new PropertyMetadata(ChooseBoxType.SingleFile));
#endregion
#region ChooseButtonWidth
public double ChooseButtonWidth
{
get { return (double)GetValue(ChooseButtonWidthProperty); }
set { SetValue(ChooseButtonWidthProperty, value); }
}
public static readonly DependencyProperty ChooseButtonWidthProperty = DependencyProperty.Register(
nameof(ChooseButtonWidth),
typeof(double),
typeof(ChooseBox),
new PropertyMetadata(20d));
#endregion
#region ChooseBoxFilter
public string Filter { get { return (string)GetValue(FilterProperty); } set { SetValue(FilterProperty, value); } }
public static readonly DependencyProperty FilterProperty = DependencyProperty.Register(
nameof(Filter),
typeof(string),
typeof(ChooseBox),
new PropertyMetadata("文本文件|*.*"));
#endregion
#region DefaultFileName
public string DefaultFileName
{
get { return (string)GetValue(DefaultFileNameProperty); }
set { SetValue(DefaultFileNameProperty, value); }
}
public static readonly DependencyProperty DefaultFileNameProperty = DependencyProperty.Register(
nameof(DefaultFileName),
typeof(string),
typeof(ChooseBox),
new PropertyMetadata("文件"));
#endregion
#region DefaultExt
public string DefaultExt
{
get { return (string)GetValue(DefaultExtProperty); }
set { SetValue(DefaultExtProperty, value); }
}
public static readonly DependencyProperty DefaultExtProperty = DependencyProperty.Register(
nameof(DefaultExt),
typeof(string),
typeof(ChooseBox),
new PropertyMetadata(string.Empty));
#endregion
}

View File

@@ -0,0 +1,146 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:WPFluent.Controls">
<ResourceDictionary.MergedDictionaries>
<!--<ResourceDictionary Source="pack://application:,,,/WPFluent;component/Resources/DesignTime.xaml" />-->
<ResourceDictionary Source="pack://application:,,,/WPFluent;component/Resources/Variables.xaml" />
</ResourceDictionary.MergedDictionaries>
<PathGeometry x:Key="icon" Figures="M147.01175 430.890704c-44.791136 0-81.108273 36.303834-81.108273 81.109296 0 44.778856 36.316114 81.108273 81.108273 81.108273 44.792159 0 81.109296-36.329417 81.109296-81.108273C228.121046 467.194538 191.804932 430.890704 147.01175 430.890704zM511.999488 430.890704c-44.791136 0-81.108273 36.303834-81.108273 81.109296 0 44.778856 36.316114 81.108273 81.108273 81.108273 44.792159 0 81.109296-36.329417 81.109296-81.108273C593.108784 467.194538 556.791647 430.890704 511.999488 430.890704zM876.987227 430.890704c-44.791136 0-81.108273 36.303834-81.108273 81.109296 0 44.778856 36.316114 81.108273 81.108273 81.108273s81.108273-36.329417 81.108273-81.108273C958.094476 467.194538 921.778362 430.890704 876.987227 430.890704z" />
<Style TargetType="{x:Type controls:ChooseBox}">
<Setter Property="ChooseButtonWidth" Value="20" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="FrameworkElement.FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
<Setter Property="FrameworkElement.ContextMenu" Value="{DynamicResource DefaultControlContextMenu}" />
<Setter Property="Foreground" Value="{DynamicResource TextControlForeground}" />
<Setter Property="TextBoxBase.CaretBrush" Value="{DynamicResource TextControlForeground}" />
<Setter Property="Background" Value="{DynamicResource TextControlBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource TextControlElevationBorderBrush}" />
<Setter Property="BorderThickness" Value="{StaticResource TextBoxBorderThemeThickness}" />
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="MinHeight" Value="{DynamicResource TextControlThemeMinHeight}" />
<Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" />
<Setter Property="Padding" Value="{DynamicResource TextControlThemePadding}" />
<Setter Property="Border.CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:ChooseBox}">
<Grid>
<Border
Name="ContentBorder"
MinWidth="{TemplateBinding MinWidth}"
MinHeight="{TemplateBinding MinHeight}"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<controls:PassiveScrollViewer
Name="PART_ContentHost"
Margin="{TemplateBinding Padding}"
Foreground="{TemplateBinding Foreground}"
IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
IsTabStop="{TemplateBinding ScrollViewer.IsTabStop}"
ScrollViewer.CanContentScroll="{TemplateBinding ScrollViewer.CanContentScroll}"
ScrollViewer.HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
ScrollViewer.VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
Style="{DynamicResource DefaultTextBoxScrollViewerStyle}" />
<Button
x:Name="PART_ChooseButton"
Grid.Column="1"
Width="{TemplateBinding ChooseButtonWidth}"
Foreground="{TemplateBinding BorderBrush}"
Style="{TemplateBinding ChooseButtonStyle}" />
</Grid>
</Border>
<Border
Name="AccentBorder"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderBrush="{DynamicResource ControlStrokeColorDefaultBrush}"
BorderThickness="{StaticResource TextBoxAccentBorderThemeThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}" />
</Grid>
<ControlTemplate.Triggers>
<!--<Trigger Property="IsKeyboardFocused" Value="true">
<Setter TargetName="bordermove" Property="Opacity" Value="1" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="bordermove" Property="Opacity" Value="1" />
</Trigger>-->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsEnabled" Value="True" />
<Condition Property="UIElement.IsMouseOver" Value="True" />
<Condition Property="UIElement.IsFocused" Value="False" />
</MultiTrigger.Conditions>
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundPointerOver}" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundDisabled}" />
<Setter TargetName="ContentBorder" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushDisabled}" />
<Setter TargetName="AccentBorder" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushDisabled}" />
<Setter Property="Foreground" Value="{DynamicResource TextControlForegroundDisabled}" />
<Setter Property="controls:TextBoxEx.ClearButtonEnabled" Value="False" />
</Trigger>
<Trigger Property="UIElement.IsFocused" Value="True">
<Setter TargetName="AccentBorder" Property="BorderThickness" Value="0,0,0,2" />
<Setter TargetName="AccentBorder" Property="BorderBrush" Value="{DynamicResource TextControlFocusedBorderBrush}" />
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundFocused}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ChooseButtonStyle">
<Setter.Value>
<Style TargetType="Button">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Path
x:Name="icon"
Width="12"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Data="{StaticResource icon}"
Fill="{StaticResource TextControlElevationBorderBrush}"
Stretch="Uniform" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand" />
<Setter TargetName="icon" Property="Fill" Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,9 @@
namespace WPFluent.Controls;
public enum ChooseBoxType
{
SingleFile,
MultiFile,
Folder,
SaveFile,
}