整合自定义控件

This commit is contained in:
GG Z
2025-08-12 23:08:54 +08:00
parent f209e7d3ad
commit d0cfc64450
520 changed files with 30954 additions and 38968 deletions

View File

@@ -6,7 +6,6 @@ using System.Windows.Automation;
using System.Windows.Automation.Peers;
using WPFluent.Controls;
namespace WPFluent.Controls;

View File

@@ -13,8 +13,8 @@ public class ChooseBox : System.Windows.Controls.TextBox
public string PlaceholderText
{
get { return (string)GetValue(PlaceholderTextProperty); }
set { SetValue(PlaceholderTextProperty, value); }
get => (string)GetValue(PlaceholderTextProperty);
set => SetValue(PlaceholderTextProperty, value);
}
public static readonly DependencyProperty PlaceholderTextProperty =
@@ -93,8 +93,8 @@ public class ChooseBox : System.Windows.Controls.TextBox
/// </summary>
public Style ChooseButtonStyle
{
get { return (Style)GetValue(ChooseButtonStyleProperty); }
set { SetValue(ChooseButtonStyleProperty, value); }
get => (Style)GetValue(ChooseButtonStyleProperty);
set => SetValue(ChooseButtonStyleProperty, value);
}
public static readonly DependencyProperty ChooseButtonStyleProperty = DependencyProperty.Register(
@@ -106,8 +106,8 @@ public class ChooseBox : System.Windows.Controls.TextBox
#region ChooseBoxType
public ChooseType ChooseType
{
get { return (ChooseType)GetValue(ChooseTypeProperty); }
set { SetValue(ChooseTypeProperty, value); }
get => (ChooseType)GetValue(ChooseTypeProperty);
set => SetValue(ChooseTypeProperty, value);
}
public static readonly DependencyProperty ChooseTypeProperty = DependencyProperty.Register(
@@ -142,8 +142,8 @@ public class ChooseBox : System.Windows.Controls.TextBox
#region ChooseButtonWidth
public double ChooseButtonWidth
{
get { return (double)GetValue(ChooseButtonWidthProperty); }
set { SetValue(ChooseButtonWidthProperty, value); }
get => (double)GetValue(ChooseButtonWidthProperty);
set => SetValue(ChooseButtonWidthProperty, value);
}
public static readonly DependencyProperty ChooseButtonWidthProperty = DependencyProperty.Register(
@@ -154,7 +154,9 @@ public class ChooseBox : System.Windows.Controls.TextBox
#endregion
#region ChooseBoxFilter
public string Filter { get { return (string)GetValue(FilterProperty); } set { SetValue(FilterProperty, value); } }
public string Filter { get => (string)GetValue(FilterProperty);
set => SetValue(FilterProperty, value);
}
public static readonly DependencyProperty FilterProperty = DependencyProperty.Register(
nameof(Filter),
@@ -166,8 +168,8 @@ public class ChooseBox : System.Windows.Controls.TextBox
#region DefaultFileName
public string DefaultFileName
{
get { return (string)GetValue(DefaultFileNameProperty); }
set { SetValue(DefaultFileNameProperty, value); }
get => (string)GetValue(DefaultFileNameProperty);
set => SetValue(DefaultFileNameProperty, value);
}
public static readonly DependencyProperty DefaultFileNameProperty = DependencyProperty.Register(
@@ -180,8 +182,8 @@ public class ChooseBox : System.Windows.Controls.TextBox
#region DefaultExt
public string DefaultExt
{
get { return (string)GetValue(DefaultExtProperty); }
set { SetValue(DefaultExtProperty, value); }
get => (string)GetValue(DefaultExtProperty);
set => SetValue(DefaultExtProperty, value);
}
public static readonly DependencyProperty DefaultExtProperty = DependencyProperty.Register(

View File

@@ -8,7 +8,6 @@ using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using WPFluent.Controls;
using MessageBoxButton = System.Windows.MessageBoxButton;
using MessageBoxResult = System.Windows.MessageBoxResult;

View File

@@ -1,5 +1,4 @@
using WPFluent.Controls;
using System;
using System.Globalization;

View File

@@ -372,18 +372,6 @@ public partial class NumberBox : TextBox
_valueUpdating = false;
}
/*/// <inheritdoc />
protected override void OnTextChanged(System.Windows.Controls.TextChangedEventArgs e)
{
base.OnTextChanged(e);
//if (new string[] { ",", ".", " " }.Any(s => Text.EndsWith(s)))
// return;
//if (!_textUpdating)
// UpdateValueToText();
}*/
/// <inheritdoc/>
public override void OnApplyTemplate()
{

View File

@@ -1,8 +1,4 @@
using System.Windows.Data;
using System.Windows.Data;
using WPFluent.Controls;

View File

@@ -8,7 +8,7 @@ using System.Text;
namespace WPFluent.Extensions;
/// <summary>
/// Set of extensions for the enumeration of icons to facilitate their management and replacement.
/// 用于枚举图标的扩展集,以方便其管理和替换。
/// </summary>
public static class SymbolExtensions
{

View File

@@ -0,0 +1,94 @@
using System.ComponentModel;
using System.Reflection;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Markup;
namespace WPFluent.Markup
{
/// <summary>
/// 枚举类作为数据源
/// </summary>
public class EnumSourceExtension : MarkupExtension
{
private Type enumType;
public bool BindToDescription { get; set; } = false;
public Type EnumType
{
get { return enumType; }
set
{
if (value != enumType)
{
if (null != value)
{
var enumType = Nullable.GetUnderlyingType(value) ?? value;
if (!enumType.IsEnum)
{
throw new ArgumentException("类型必须是枚举类型");
}
}
enumType = value;
}
}
}
/// <summary>
/// 在ResouceDictionary中声明
/// </summary>
/// <example><c>local:EnumSourceExtension x:Key="EnumBindingSource" EnumType="{x:Type local:Sex}"</c></example>
/// <example><c>ItemsSource="{local:EnumSource EnumType=local:ExampleEnum}" SelectedItem="{Binding ExampleEnum}"</c></example>
public EnumSourceExtension()
{
}
/// <summary>
/// 用Markup语法
/// </summary>
/// <param name="enumType"></param>
/// <remarks>若需要绑定Description则需设置BindToDescription为True同时只能用SelectedValue来绑定源属性</remarks>
/// <example><c>ItemsSource="{Binding Source={local:EnumTypeBindingSource {x:Type local:ExampleEnum}}}"</c></example>
public EnumSourceExtension(Type enumType) { EnumType = enumType; }
public override object ProvideValue(IServiceProvider serviceProvider)
{
var pvt = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget));
if (pvt == null) { return null; }
//如果为空,则返回运行时绑定的类。
if (pvt.TargetObject is not FrameworkElement) { return this; }
var enumValues = Enum.GetValues(enumType);
if (BindToDescription)
{
var items = new List<object>();
foreach (var enumValue in enumValues)
{
var item = new
{
Value = enumValue,
Description = GetDescription(enumValue)
};
items.Add(item);
}
if (pvt.TargetObject is Selector selector)
{
selector.DisplayMemberPath = "Description";
selector.SelectedValuePath = "Value";
}
return items;
}
return enumValues;
}
private static string GetDescription(object enumValue)
{
var fieldInfo = enumValue.GetType().GetField(enumValue.ToString());
var descriptionAttribute = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
return descriptionAttribute?.Description ?? enumValue.ToString();
}
}
}

View File

@@ -13,7 +13,7 @@
<!-- Layout -->
<!-- Controls -->
<ResourceDictionary Source="pack://application:,,,/WPFluent;component/Controls/FontIcon/FontIconFallback.xaml" />
<ResourceDictionary Source="pack://application:,,,/WPFluent;component/Controls/IconElement/FontIconFallback.xaml" />
<ResourceDictionary Source="pack://application:,,,/WPFluent;component/Controls/Button/Button.xaml" />
<ResourceDictionary Source="pack://application:,,,/WPFluent;component/Controls/AccessText/AccessText.xaml" />
<ResourceDictionary Source="pack://application:,,,/WPFluent;component/Controls/Anchor/Anchor.xaml" />