整理控件库

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

@@ -7,8 +7,8 @@ using System.Windows.Data;
namespace WPFluent.Controls
{
[TemplatePart(Name = FilterTextBox, Type = typeof(WPFluent.Controls.TextBox))]
[TemplatePart(Name = "PART_EditableTextBox", Type = typeof(WPFluent.Controls.TextBox))]
[TemplatePart(Name = FilterTextBox, Type = typeof(System.Windows.Controls.TextBox))]
[TemplatePart(Name = "PART_EditableTextBox", Type = typeof(System.Windows.Controls.TextBox))]
public class ComboBoxEx : ComboBox
{
private const string FilterTextBox = "PART_FilterTextBox";
@@ -45,7 +45,7 @@ namespace WPFluent.Controls
new PropertyMetadata(true));
private TextBox filterTextBox;
private System.Windows.Controls.TextBox filterTextBox;
private ICollectionView view;
static ComboBoxEx()
@@ -62,14 +62,14 @@ namespace WPFluent.Controls
/// <param name="e"></param>
private void PART_FilterTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if(filterTextBox == null)
if (filterTextBox == null)
return;
if(view != null)
if (view != null)
{
view.Filter += (o) =>
{
if(o is string)
if (o is string)
{
var value = o.ToString().ToLower();
return value.IndexOf(filterTextBox.Text.ToLower(), StringComparison.Ordinal) != -1;
@@ -78,7 +78,7 @@ namespace WPFluent.Controls
{
var obj = GetPropertyValue(o, DisplayMemberPath);
//在xaml中写入Combobox时
if(obj is ComboBoxItem item)
if (obj is ComboBoxItem item)
{
obj = item.Content;
}
@@ -118,31 +118,33 @@ namespace WPFluent.Controls
/// </summary>
public static object GetPropertyValue(object obj, string path)
{
if(obj == null)
if (obj == null)
return string.Empty;
var result = obj;
if(!string.IsNullOrEmpty(path))
if (!string.IsNullOrEmpty(path))
{
var property = obj.GetType().GetProperty(path);
if(property != null)
if (property != null)
{
try
{
result = property.GetValue(obj, null);
return result;
} catch
}
catch
{
try
{
var type = obj.GetType();
var mInfo = type.GetMethod($"get_{path}");
if(mInfo != null)
if (mInfo != null)
{
result = mInfo.Invoke(obj, null);
return result;
}
} catch
}
catch
{
}
}
@@ -158,13 +160,13 @@ namespace WPFluent.Controls
{
base.OnApplyTemplate();
if(filterTextBox != null)
if (filterTextBox != null)
{
filterTextBox.TextChanged -= PART_FilterTextBox_TextChanged;
}
filterTextBox = GetTemplateChild(FilterTextBox) as TextBox;
if(filterTextBox != null)
filterTextBox = GetTemplateChild(FilterTextBox) as System.Windows.Controls.TextBox;
if (filterTextBox != null)
{
filterTextBox.TextChanged += PART_FilterTextBox_TextChanged;
}

View File

@@ -29,17 +29,17 @@
<Setter Property="ContextMenu" Value="{DynamicResource DefaultControlContextMenu}" />
<!-- Universal WPF UI ContextMenu -->
<Setter Property="Background" Value="{DynamicResource ComboBoxBackground}" />
<Setter Property="Border.CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
<Setter Property="Border.CornerRadius" Value="{StaticResource ControlCornerRadius}" />
<Setter Property="BorderBrush" Value="{DynamicResource ControlElevationBorderBrush}" />
<Setter Property="BorderThickness" Value="{StaticResource ComboBoxBorderThemeThickness}" />
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
<Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}" />
<Setter Property="Foreground" Value="{DynamicResource ComboBoxForeground}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="MinHeight" Value="{DynamicResource TextControlThemeMinHeight}" />
<Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" />
<Setter Property="MinHeight" Value="{StaticResource TextControlThemeMinHeight}" />
<Setter Property="MinWidth" Value="{StaticResource TextControlThemeMinWidth}" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Padding" Value="{DynamicResource ComboBoxPadding}" />
<Setter Property="Padding" Value="{StaticResource ComboBoxPadding}" />
<Setter Property="Popup.Placement" Value="Bottom" />
<Setter Property="Popup.PopupAnimation" Value="Slide" />
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
@@ -49,7 +49,6 @@
<Setter Property="VerticalAlignment" Value="Center" />
<!-- WPF 不喜欢居中,动画很难看,鼠标按钮有时会立即点击。 -->
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:ComboBoxEx}">
@@ -78,11 +77,11 @@
Grid.Row="0"
MinWidth="{TemplateBinding MinWidth}"
MinHeight="{TemplateBinding MinHeight}"
Padding="0"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}">
CornerRadius="{TemplateBinding Border.CornerRadius}"
Padding="0">
<Grid>
<!--
Chevron 位于 Presenter 上ToggleButton 位于 Chevron 上TextBox 位于 ToggleButton 上。
@@ -98,24 +97,34 @@
<!--#region 扩展水印-->
<TextBlock
x:Name="PlaceholderTextBlock"
Padding="1,0"
VerticalAlignment="Center"
Focusable="False"
FontSize="{TemplateBinding FontSize}"
Foreground="{DynamicResource TextControlPlaceholderForeground}"
IsHitTestVisible="False"
Padding="1,0"
Text="{TemplateBinding PlaceholderText}"
Visibility="Collapsed" />
<!--#endregion-->
<ContentPresenter
Name="PART_ContentPresenter"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
IsHitTestVisible="False"
Name="PART_ContentPresenter"
TextElement.Foreground="{TemplateBinding Foreground}" />
</Grid>
<!-- 可编辑时 -->
<ToggleButton
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="0"
ClickMode="Press"
Focusable="False"
Foreground="{TemplateBinding Foreground}"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Name="ToggleButton"
Style="{StaticResource DefaultComboBoxToggleButtonStyle}" />
<TextBox
x:Name="PART_EditableTextBox"
Grid.Column="0"
@@ -131,22 +140,13 @@
VerticalAlignment="Center"
FontSize="{StaticResource ComboBoxChevronSize}"
Foreground="{DynamicResource ComboBoxDropDownGlyphForeground}"
IsHitTestVisible="False"
RenderTransformOrigin="0.5, 0.5"
Symbol="ChevronDown24">
<controls:SymbolIcon.RenderTransform>
<RotateTransform Angle="0" />
</controls:SymbolIcon.RenderTransform>
</controls:SymbolIcon>
<ToggleButton
Name="ToggleButton"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="0"
ClickMode="Press"
Focusable="False"
Foreground="{TemplateBinding Foreground}"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource DefaultComboBoxToggleButtonStyle}" />
</Grid>
<!-- 弹出式菜单 -->
<Popup
@@ -161,25 +161,25 @@
VerticalOffset="1">
<Border
x:Name="DropDownBorder"
Padding="0,4,0,6"
Background="{DynamicResource ComboBoxDropDownBackground}"
BorderBrush="{DynamicResource ComboBoxDropDownBorderBrush}"
BorderThickness="1"
CornerRadius="{DynamicResource PopupCornerRadius}"
CornerRadius="{StaticResource PopupCornerRadius}"
Padding="0,4,0,6"
SnapsToDevicePixels="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Margin="5,2,5,2" Visibility="{Binding ShowFilterBox, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisConverter}}">
<TextBox x:Name="PART_FilterTextBox" Margin="0" />
<TextBox x:Name="PART_FilterTextBox"/>
<TextBlock
Name="FilterPlaceholderTextBlock"
Padding="14,0"
VerticalAlignment="Center"
Foreground="{DynamicResource TextControlPlaceholderForeground}"
IsHitTestVisible="False"
Name="FilterPlaceholderTextBlock"
Padding="14,0"
Text="{TemplateBinding FilterBoxPlaceholderText}"
TextBlock.FontSize="{TemplateBinding FontSize}"
Visibility="Collapsed" />
@@ -218,17 +218,17 @@
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Duration="00:00:00.167"
From="0"
Storyboard.TargetName="ChevronIcon"
Storyboard.TargetProperty="(controls:SymbolIcon.RenderTransform).(RotateTransform.Angle)"
From="0"
To="180"
Duration="00:00:00.167" />
To="180" />
<DoubleAnimation
Duration="00:00:00.167"
From="-90"
Storyboard.TargetName="DropDownBorder"
Storyboard.TargetProperty="(Border.RenderTransform).(TranslateTransform.Y)"
From="-90"
To="0"
Duration="00:00:00.167">
To="0">
<DoubleAnimation.EasingFunction>
<CircleEase EasingMode="EaseOut" />
</DoubleAnimation.EasingFunction>
@@ -240,16 +240,16 @@
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Duration="00:00:00.167"
From="180"
Storyboard.TargetName="ChevronIcon"
Storyboard.TargetProperty="(controls:SymbolIcon.RenderTransform).(RotateTransform.Angle)"
From="180"
To="0"
Duration="00:00:00.167" />
To="0" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
<Trigger SourceName="PART_FilterTextBox" Property="Text" Value="">
<Trigger Property="Text" Value="" SourceName="PART_FilterTextBox">
<Setter TargetName="FilterPlaceholderTextBlock" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="Header" Value="{x:Null}">
@@ -266,7 +266,7 @@
<Trigger Property="HasItems" Value="False">
<Setter TargetName="DropDownBorder" Property="MinHeight" Value="{StaticResource ComboBoxPopupMinHeight}" />
</Trigger>
<Trigger SourceName="PART_Popup" Property="Popup.AllowsTransparency" Value="False">
<Trigger Property="Popup.AllowsTransparency" Value="False" SourceName="PART_Popup">
<Setter TargetName="DropDownBorder" Property="CornerRadius" Value="0" />
</Trigger>
<Trigger Property="IsGrouping" Value="True">
@@ -336,6 +336,7 @@
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="VerticalContentAlignment" Value="Top" />
</Style>
<!--<Style BasedOn="{StaticResource DefaultComboBoxItemStyle}" TargetType="{x:Type ComboBoxItem}" />-->