优化更新代码,添加界面功能并整合
This commit is contained in:
9
WPFluent/Models/ColorTypeEnum.cs
Normal file
9
WPFluent/Models/ColorTypeEnum.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace WPFluent.Models
|
||||
{
|
||||
public enum ColorTypeEnum
|
||||
{
|
||||
RGB,
|
||||
HSL,
|
||||
HEX
|
||||
}
|
||||
}
|
||||
37
WPFluent/Models/Hsb.cs
Normal file
37
WPFluent/Models/Hsb.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
namespace WPFluent.Models
|
||||
{
|
||||
public struct Hsb
|
||||
{
|
||||
public Hsb(double Hue, double Saturation, double Brightness, double opacity = 1)
|
||||
{
|
||||
this.Hue = Hue;
|
||||
this.Saturation = Saturation;
|
||||
this.Brightness = Brightness;
|
||||
this.Opacity = opacity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 亮度0~1
|
||||
/// </summary>
|
||||
public double Brightness { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 色相0~359
|
||||
/// </summary>
|
||||
public double Hue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 不透明度0~1
|
||||
/// </summary>
|
||||
public double Opacity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 饱和度0~1
|
||||
/// </summary>
|
||||
public double Saturation { get; set; }
|
||||
//public override string ToString()
|
||||
//{
|
||||
// return base.ToString();
|
||||
//}
|
||||
}
|
||||
}
|
||||
193
WPFluent/Models/TreeModel.cs
Normal file
193
WPFluent/Models/TreeModel.cs
Normal file
@@ -0,0 +1,193 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace WPFluent.Models;
|
||||
|
||||
|
||||
public partial class TreeModel : INotifyPropertyChanged, IComparable
|
||||
{
|
||||
private bool? isChecked;
|
||||
|
||||
|
||||
private bool isExpanded;
|
||||
|
||||
/// <summary>
|
||||
/// 构造
|
||||
/// </summary>
|
||||
public TreeModel()
|
||||
{
|
||||
Children = new ObservableCollection<TreeModel>();
|
||||
IsChecked = false;
|
||||
//Icon = "./Resources/File_16px.png";
|
||||
//TitleIcon = FamilyPlugins.Properties.Resources.Folder_32px;
|
||||
IsExpanded = false;
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
protected void SetProperty<T>(ref T prop, T value, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if(EqualityComparer<T>.Default.Equals(prop, value) == false)
|
||||
{
|
||||
prop = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
var treeModel = (TreeModel)obj;
|
||||
|
||||
int result;
|
||||
if(Name == treeModel.Name)
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = Name.CompareTo(treeModel.Name) > 0 ? 1 : -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual void OnPropertyChanged(string propertyName)
|
||||
{ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); }
|
||||
|
||||
/// <summary>
|
||||
/// 设置所有子项的选中状态
|
||||
/// </summary>
|
||||
public void SetChildrenChecked()
|
||||
{
|
||||
if(Children != null && Children.Count > 0 && IsChecked != null)
|
||||
{
|
||||
foreach(var child in Children)
|
||||
{
|
||||
child.IsChecked = IsChecked;
|
||||
if(child.Children != null && Children.Count > 0)
|
||||
{
|
||||
child.SetChildrenChecked();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置所有子项的选中状态
|
||||
/// </summary>
|
||||
/// <param name="isCheck"></param>
|
||||
public void SetChildrenChecked(bool isCheck)
|
||||
{
|
||||
if(Children != null && Children.Count > 0)
|
||||
{
|
||||
foreach(var child in Children)
|
||||
{
|
||||
child.IsChecked = isCheck;
|
||||
if(child.Children != null && Children.Count > 0)
|
||||
{
|
||||
child.SetChildrenChecked(isCheck);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置所有子项展开状态
|
||||
/// </summary>
|
||||
/// <param name="isExpanded"></param>
|
||||
public void SetChildrenExpanded(bool isExpanded)
|
||||
{
|
||||
foreach(var child in Children)
|
||||
{
|
||||
child.IsExpanded = isExpanded;
|
||||
child.SetChildrenExpanded(isExpanded);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使父节点处于选中状态
|
||||
/// </summary>
|
||||
public void SetParentChecked()
|
||||
{
|
||||
if(Parent != null)
|
||||
{
|
||||
if(Parent.Children.Count(c => c.IsChecked == null) > 0)
|
||||
{
|
||||
Parent.IsChecked = null;
|
||||
}
|
||||
else if(Parent.Children.Count(c => c.IsChecked == true) == 0)
|
||||
{
|
||||
Parent.IsChecked = false;
|
||||
}
|
||||
else if(Parent.Children.Count(c => c.IsChecked == true) == Parent.Children.Count)
|
||||
{
|
||||
Parent.IsChecked = true;
|
||||
}
|
||||
else if(Parent.Children.Count(c => c.IsChecked == true) < Parent.Children.Count)
|
||||
{
|
||||
Parent.IsChecked = null;
|
||||
}
|
||||
|
||||
if(Parent.Parent != null)
|
||||
{
|
||||
Parent.SetParentChecked();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 子项
|
||||
/// </summary>
|
||||
public IList<TreeModel> Children { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图标
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 键值
|
||||
/// </summary>
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 选中状态
|
||||
/// </summary>
|
||||
public bool? IsChecked { get => isChecked; set => SetProperty(ref isChecked, value); }
|
||||
|
||||
/// <summary>
|
||||
/// 折叠状态
|
||||
/// </summary>
|
||||
public bool IsExpanded { get => isExpanded; set => SetProperty(ref isExpanded, value); }
|
||||
|
||||
/// <summary>
|
||||
/// 显示的字符
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 父项
|
||||
/// </summary>
|
||||
public TreeModel Parent { get; set; }
|
||||
|
||||
public object Tag { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 指针悬停时的显示说明
|
||||
/// </summary>
|
||||
public string ToolTip
|
||||
{
|
||||
get
|
||||
{
|
||||
return Parent == null ? $"{Name}" : $"{Parent.Name}-{Name}";
|
||||
//return String.Format(Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user