This commit is contained in:
GG Z
2026-01-02 16:37:37 +08:00
parent 4df4ce1e6a
commit 0e9db9a2b9
80 changed files with 1846 additions and 4570 deletions

View File

@@ -86,7 +86,7 @@ namespace NeoUI.Appearance
{
foreach (var key in dict.Keys.OfType<object>())
{
if (dict[key] is SolidColorBrush && key != null)
if (dict[key] is SolidColorBrush)
keys.Add(key.ToString());
}
}

View File

@@ -118,17 +118,18 @@ public class Breadcrumb : ItemsControl
{
base.OnItemsChanged(e);
if(e.OldItems is { })
if (e.OldItems is null) return;
if (e.NewItems != null)
{
foreach(var item in e.NewItems.OfType<BreadcrumbItem>())
foreach (var item in e.NewItems.OfType<BreadcrumbItem>())
{
item.Navigate += BreadcrumbItem_Navigate;
}
}
foreach(var item in e.OldItems.OfType<BreadcrumbItem>())
{
item.Navigate -= BreadcrumbItem_Navigate;
}
foreach(var item in e.OldItems.OfType<BreadcrumbItem>())
{
item.Navigate -= BreadcrumbItem_Navigate;
}
}

View File

@@ -237,8 +237,8 @@ public class ColorPanel : Control
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
colorCanvas = (Canvas)GetTemplateChild("PART_ColorCanvas");
colorSelector = (Thumb)GetTemplateChild("PART_ColorSelector");
colorCanvas = (Canvas?)GetTemplateChild("PART_ColorCanvas");
colorSelector = (Thumb?)GetTemplateChild("PART_ColorSelector");
if (colorSelector == null || colorCanvas == null) return;
colorSelector.DragDelta += ColorSelector_DragDelta;
colorCanvas.MouseLeftButtonDown += ColorCanvas_MouseLeftButtonDown;

View File

@@ -23,7 +23,7 @@ public class Hyperlink : ButtonBase
/// 定义私有的 Key这是“写入权限”的钥匙只有在这个类内部才能拿到
/// </summary>
public static readonly DependencyProperty IsVisitedProperty =
IsVisitedPropertyKey?.DependencyProperty;
IsVisitedPropertyKey.DependencyProperty;
/// <summary>
/// 表示已经浏览过的依赖属性。
/// </summary>
@@ -63,20 +63,18 @@ public class Hyperlink : ButtonBase
{
base.OnMouseLeftButtonDown(e);
if (!string.IsNullOrEmpty(NavigateUri))
if (string.IsNullOrEmpty(NavigateUri)) return;
try
{
try
{
// 1. 打开网页
Process.Start(new ProcessStartInfo(NavigateUri) { UseShellExecute = true });
// 1. 打开网页
Process.Start(new ProcessStartInfo(NavigateUri) { UseShellExecute = true });
// 2. 改变自身状态(这就是你作为控件的“记忆”)
SetValue(IsVisitedPropertyKey, true);
}
catch
{
// 忽略无效链接异常
}
// 2. 改变自身状态(这就是你作为控件的“记忆”)
SetValue(IsVisitedPropertyKey, true);
}
catch
{
// 忽略无效链接异常
}
}
}

View File

@@ -610,7 +610,7 @@ public class MultiComboBox : Control
else
{
// 优化多选同步算法,避免每次都 ToList()
var sourceList = SelectedItems as IList;
var sourceList = SelectedItems;
if (sourceList == null) return;
// 使用 HashSet 提高查找速度 O(1)
@@ -763,7 +763,7 @@ public class MultiComboBox : Control
}
// 处理第一个元素
if (IsMatch(firstItem, filter, propDesc)) filtered.Add(firstItem);
if (IsMatch(firstItem, filter!, propDesc)) filtered.Add(firstItem);
}
// 处理剩余元素
@@ -777,7 +777,7 @@ public class MultiComboBox : Control
}
// 辅助方法,内联以减少调用开销
private bool IsMatch(object? item, string filter, PropertyDescriptor? propDesc)
private static bool IsMatch(object? item, string filter, PropertyDescriptor? propDesc)
{
if (item == null) return false;
string? value;

View File

@@ -197,21 +197,18 @@ public class NeoWindow : Window
stateName = "Normal";
}
//VisualStateManager.GoToState(maximizeRestoreButton, stateName, true);
switch (stateName)
maximizeRestoreButton?.Background = stateName switch
{
case "Pressed":
"Pressed" =>
//VisualStateManager.GoToState(maximizeRestoreButton, "Pressed", true);
maximizeRestoreButton.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#33000000"));
break;
case "MouseOver":
maximizeRestoreButton.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#1A000000"));
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#33000000")),
"MouseOver" =>
//VisualStateManager.GoToState(maximizeRestoreButton, "MouseOver", true);
break;
case "Normal":
maximizeRestoreButton.Background = Brushes.Transparent;
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#1A000000")),
"Normal" => Brushes.Transparent,
//VisualStateManager.GoToState(maximizeRestoreButton, "Normal", true);
break;
}
_ => maximizeRestoreButton?.Background
};
}
#region Window Control Methods

View File

@@ -66,36 +66,33 @@ namespace NeoUI.Markup
//如果为空,则返回运行时绑定的类。
if (pvt.TargetObject is not FrameworkElement) { return this; }
if (enumType != null)
if (enumType == null) return null;
var enumValues = Enum.GetValues(enumType);
if (!BindToDescription) return enumValues;
var items = new List<object>();
foreach (var enumValue in enumValues)
{
var enumValues = Enum.GetValues(enumType);
if (!BindToDescription) return enumValues;
var items = new List<object>();
foreach (var enumValue in enumValues)
var item = new
{
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;
Value = enumValue,
Description = GetDescription(enumValue)
};
items.Add(item);
}
return null;
if (pvt.TargetObject is Selector selector)
{
selector.DisplayMemberPath = "Description";
selector.SelectedValuePath = "Value";
}
return items;
}
private static string GetDescription(object enumValue)
private static string? GetDescription(object? enumValue)
{
if (enumValue == null) return string.Empty;
var fieldInfo = enumValue.GetType().GetField(enumValue.ToString());
var fieldInfo = enumValue.GetType().GetField(enumValue.ToString() ?? string.Empty);
var descriptionAttribute = fieldInfo?.GetCustomAttribute<DescriptionAttribute>();
return descriptionAttribute?.Description ?? enumValue.ToString();

View File

@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>net462;net8.0-windows</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>13.0</LangVersion>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<Version>1.0.0</Version>