整理控件库

This commit is contained in:
GG Z
2025-05-05 17:04:06 +08:00
parent 74532b77be
commit 3eaad7566e
283 changed files with 2156 additions and 17846 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.Win32;
using Microsoft.Win32;
namespace WPFluent.Controls;
@@ -9,12 +10,24 @@ public class ChooseBox : System.Windows.Controls.TextBox
static ChooseBox()
{ DefaultStyleKeyProperty.OverrideMetadata(typeof(ChooseBox), new FrameworkPropertyMetadata(typeof(ChooseBox))); }
public string PlaceholderText
{
get { return (string)GetValue(PlaceholderTextProperty); }
set { SetValue(PlaceholderTextProperty, value); }
}
public static readonly DependencyProperty PlaceholderTextProperty =
DependencyProperty.Register("PlaceholderText", typeof(string), typeof(ChooseBox), new PropertyMetadata(string.Empty));
#region Event Implement Function
private void PART_ChooseButton_Click(object sender, RoutedEventArgs e)
{
switch (ChooseBoxType)
switch (ChooseType)
{
case ChooseBoxType.SingleFile:
case ChooseType.SingleFile:
OpenFileDialog openFileDialog =
new()
{
@@ -25,7 +38,7 @@ public class ChooseBox : System.Windows.Controls.TextBox
if (openFileDialog.ShowDialog() == true)
this.Text = openFileDialog.FileName;
break;
case ChooseBoxType.MultiFile:
case ChooseType.MultiFiles:
OpenFileDialog multiFileDialog =
new()
{
@@ -37,17 +50,17 @@ public class ChooseBox : System.Windows.Controls.TextBox
string fileName = string.Empty;
foreach (var item in multiFileDialog.FileNames)
{
fileName += item + ";";
fileName += $"{item};";
}
this.Text = fileName.TrimEnd(';');
}
break;
case ChooseBoxType.Folder:
case ChooseType.Folder:
var folderDialog = new VistaFolderBrowserDialog();
if (folderDialog.ShowDialog() == true)
this.Text = folderDialog.SelectedPath;
break;
case ChooseBoxType.SaveFile:
case ChooseType.SaveFile:
var fileDialog = new SaveFileDialog
{
Filter = Filter, //设置文件类型
@@ -91,17 +104,39 @@ public class ChooseBox : System.Windows.Controls.TextBox
#endregion
#region ChooseBoxType
public ChooseBoxType ChooseBoxType
public ChooseType ChooseType
{
get { return (ChooseBoxType)GetValue(ChooseBoxTypeProperty); }
set { SetValue(ChooseBoxTypeProperty, value); }
get { return (ChooseType)GetValue(ChooseTypeProperty); }
set { SetValue(ChooseTypeProperty, value); }
}
public static readonly DependencyProperty ChooseBoxTypeProperty = DependencyProperty.Register(
nameof(ChooseBoxType),
typeof(ChooseBoxType),
public static readonly DependencyProperty ChooseTypeProperty = DependencyProperty.Register(
nameof(ChooseType),
typeof(ChooseType),
typeof(ChooseBox),
new PropertyMetadata(ChooseBoxType.SingleFile));
new PropertyMetadata(ChooseType.SingleFile, OnChooseTypeChanged));
private static void OnChooseTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is ChooseBox chooseBox)
{
switch ((ChooseType)e.NewValue)
{
case ChooseType.SingleFile:
chooseBox.PlaceholderText = "请选择文件";
break;
case ChooseType.MultiFiles:
chooseBox.PlaceholderText = "请选择多个文件";
break;
case ChooseType.Folder:
chooseBox.PlaceholderText = "请选择文件夹";
break;
case ChooseType.SaveFile:
chooseBox.PlaceholderText = "请选择保存文件路径";
break;
}
}
}
#endregion
#region ChooseButtonWidth

View File

@@ -8,50 +8,84 @@
<ResourceDictionary Source="pack://application:,,,/WPFluent;component/Controls/TextBox/TextBox.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 x:Key="ChooseButtonStyle" 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="{DynamicResource 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>
<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="Border.CornerRadius" Value="{StaticResource ControlCornerRadius}" />
<Setter Property="BorderBrush" Value="{DynamicResource TextControlElevationBorderBrush}" />
<Setter Property="BorderThickness" Value="{StaticResource TextBoxBorderThemeThickness}" />
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
<Setter Property="ChooseButtonWidth" Value="20" />
<Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}" />
<Setter Property="Foreground" Value="{DynamicResource TextControlForeground}" />
<Setter Property="FrameworkElement.ContextMenu" Value="{DynamicResource DefaultControlContextMenu}" />
<Setter Property="FrameworkElement.FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="MinHeight" Value="{StaticResource TextControlThemeMinHeight}" />
<Setter Property="MinWidth" Value="{StaticResource TextControlThemeMinWidth}" />
<Setter Property="Padding" Value="{StaticResource TextControlThemePadding}" />
<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="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<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}">
CornerRadius="{TemplateBinding Border.CornerRadius}"
Name="ContentBorder"
Padding="0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<TextBlock
Visibility="Collapsed"
Margin="0"
VerticalAlignment="Center"
Foreground="{DynamicResource TextControlPlaceholderForeground}"
Name="PlaceholderTextBlock"
Padding="4,0"
Text="{TemplateBinding PlaceholderText}"
TextBlock.FontSize="{TemplateBinding FontSize}" />
<controls:PassiveScrollViewer
x:Name="PART_ContentHost"
Margin="{TemplateBinding Padding}"
@@ -67,17 +101,17 @@
Grid.Column="1"
Width="{TemplateBinding ChooseButtonWidth}"
Foreground="{TemplateBinding Foreground}"
Style="{TemplateBinding ChooseButtonStyle}" />
Style="{StaticResource ChooseButtonStyle}" />
</Grid>
</Border>
<Border
Name="AccentBorder"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderBrush="{DynamicResource ControlStrokeColorDefaultBrush}"
BorderThickness="{StaticResource TextBoxAccentBorderThemeThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}" />
CornerRadius="{TemplateBinding Border.CornerRadius}"
Name="AccentBorder" />
</Grid>
<ControlTemplate.Triggers>
<!--<Trigger Property="IsKeyboardFocused" Value="true">
@@ -94,54 +128,29 @@
</MultiTrigger.Conditions>
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundPointerOver}" />
</MultiTrigger>
<Trigger Property="Text" Value="">
<Setter TargetName="PlaceholderTextBlock" Property="Visibility" Value="Visible" />
</Trigger>
<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" />
<Setter Property="Foreground" Value="{DynamicResource TextControlForegroundDisabled}" />
</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}" />
<Setter TargetName="AccentBorder" Property="BorderBrush" Value="{DynamicResource TextControlFocusedBorderBrush}" />
<Setter TargetName="AccentBorder" Property="BorderThickness" Value="0,0,0,2" />
</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>
<Setter Property="TextBoxBase.CaretBrush" Value="{DynamicResource TextControlForeground}" />
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
</Style>
</ResourceDictionary>

View File

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