定义日志图标资源

This commit is contained in:
zengwenjie
2025-09-24 17:28:06 +08:00
parent c26fbcce22
commit 6bdb41e8b5
6 changed files with 136 additions and 17 deletions

View File

@@ -23,7 +23,7 @@ namespace Deedy.Activity
/// <summary> /// <summary>
/// 用于为Action提供显示视图 /// 用于为Action提供显示视图
/// </summary> /// </summary>
[IconKey(ThemeKeys.KEY_Activity_DefaultIcon)] [IconKey(ThemeKeys.Keys.Activity_DefaultIcon)]
[TemplatePart(Name = PART_ItemsContainer, Type = typeof(ItemsControl))] [TemplatePart(Name = PART_ItemsContainer, Type = typeof(ItemsControl))]
[TemplatePart(Name = PART_TitleContainer, Type = typeof(FrameworkElement))] [TemplatePart(Name = PART_TitleContainer, Type = typeof(FrameworkElement))]
[TemplatePart(Name = PART_StateDecorator, Type = typeof(ViewerStateDecorator))] [TemplatePart(Name = PART_StateDecorator, Type = typeof(ViewerStateDecorator))]
@@ -250,7 +250,6 @@ namespace Deedy.Activity
if (e.NewValue is LogInfo logInfo) if (e.NewValue is LogInfo logInfo)
{ {
this.ToolTip = logInfo.ToString(); this.ToolTip = logInfo.ToString();
//TODO更新消息显示图标
this.LogInfos.Add(logInfo); this.LogInfos.Add(logInfo);
} }
} }

View File

@@ -1,7 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Media; using System.Windows.Media;
@@ -9,16 +11,94 @@ using System.Windows.Shapes;
namespace Deedy.Activity namespace Deedy.Activity
{ {
public class LogInfo public class LogInfo : INotifyPropertyChanged
{ {
private LogInfo() { } #region
[AllowNull] public event PropertyChangedEventHandler? PropertyChanged;
public ImageSource Icon { get; set; } protected virtual void OnPropertyChanged([CallerMemberName, AllowNull] string propertyName = null)
public readonly static LogInfo Empty = new();
public override string ToString()
{ {
//TODO返回序列化后的消息 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
return "";
} }
protected virtual T GetField<T>(ref T field, [CallerMemberName, AllowNull] string propertyName = null)
{
T result = field;
switch (propertyName)
{
//返回前的自定义逻辑
default: break;
}
return result;
}
protected virtual bool SetField<T>(ref T field, T value, [CallerMemberName, AllowNull] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
T _Value = value;
switch (propertyName)
{
//赋值前的自定义逻辑
default: break;
}
field = _Value;
OnPropertyChanged(propertyName);
return true;
}
#endregion
public static LogInfo Empty => new("");
public LogInfo(string info, InfoType type = InfoType.) { this.Info = info; this.Type = type; }
[AllowNull]
protected internal ImageSource _Icon = null;
/// <summary>
/// 消息图标
/// </summary>
public ImageSource? Icon
{
get { return GetField<ImageSource?>(ref _Icon); }
private set
{
if (SetField<ImageSource?>(ref _Icon, value))
{
// 这里可以加入属性变更后的处理逻辑
}
}
}
protected internal InfoType _Type = InfoType.;
/// <summary>
/// 消息类型
/// </summary>
public InfoType Type
{
get { return GetField<InfoType>(ref _Type); }
set
{
if (SetField<InfoType>(ref _Type, value))
{
switch (value)
{
case InfoType.: this.Icon = new ThemeResources().InfoIcon_None; break;
case InfoType.: this.Icon = new ThemeResources().InfoIcon_Info; break;
case InfoType.: this.Icon = new ThemeResources().InfoIcon_Warning; break;
case InfoType.: this.Icon = new ThemeResources().InfoIcon_Error; break;
default: this.Icon = new ThemeResources().InfoIcon_None; break;
}
}
}
}
protected internal string _Info = "";
/// <summary>
/// 信息内容
/// </summary>
public string Info
{
get { return GetField<string>(ref _Info); }
set
{
if (SetField<string>(ref _Info, value))
{
// 这里可以加入属性变更后的处理逻辑
}
}
}
public override string ToString() => $"「{this.Type}\t」「{this.Info}」";
} }
} }

View File

@@ -8,9 +8,21 @@ namespace Deedy.Activity
{ {
public enum InfoType : int public enum InfoType : int
{ {
None = 0, /// <summary>
Info = 1, /// None
Warn = 2, /// </summary>
Error = 3 = 0,
/// <summary>
/// Info
/// </summary>
= 1,
/// <summary>
/// Warning
/// </summary>
= 2,
/// <summary>
/// Error
/// </summary>
= 3
} }
} }

View File

@@ -10,7 +10,16 @@ namespace Deedy.Activity
{ {
public static class ThemeKeys public static class ThemeKeys
{ {
public const string KEY_Activity_DefaultIcon = "Activity_DefaultIcon"; public static class Keys
{
public const string Activity_DefaultIcon = "Activity_DefaultIcon";
public const string InfoIcon_None = "InfoIcon_None";
public const string InfoIcon_Info = "InfoIcon_Info";
public const string InfoIcon_Warning = "InfoIcon_Warning";
public const string InfoIcon_Error = "InfoIcon_Error";
}
public static ComponentResourceKey? LookupResourceKey(string themeKey) public static ComponentResourceKey? LookupResourceKey(string themeKey)
{ {
if (typeof(ThemeKeys).GetProperty(themeKey, typeof(ComponentResourceKey)) is PropertyInfo pInfo) if (typeof(ThemeKeys).GetProperty(themeKey, typeof(ComponentResourceKey)) is PropertyInfo pInfo)
@@ -18,7 +27,10 @@ namespace Deedy.Activity
return null; return null;
} }
public static ComponentResourceKey Activity_DefaultIcon => new ComponentResourceKey(typeof(ThemeKeys), "Activity_DefaultIcon"); public static ComponentResourceKey Activity_DefaultIcon => new ComponentResourceKey(typeof(ThemeKeys), Keys.Activity_DefaultIcon);
public static ComponentResourceKey InfoIcon_None = new ComponentResourceKey(typeof(ThemeKeys), Keys.InfoIcon_None);
public static ComponentResourceKey InfoIcon_Info = new ComponentResourceKey(typeof(ThemeKeys), Keys.InfoIcon_Info);
public static ComponentResourceKey InfoIcon_Warning = new ComponentResourceKey(typeof(ThemeKeys), Keys.InfoIcon_Warning);
public static ComponentResourceKey InfoIcon_Error = new ComponentResourceKey(typeof(ThemeKeys), Keys.InfoIcon_Error);
} }
} }

View File

@@ -11,5 +11,9 @@ namespace Deedy.Activity
public partial class ThemeResources : ResourceDictionary public partial class ThemeResources : ResourceDictionary
{ {
public ImageSource? Activity_DefaultIcon => this[ThemeKeys.Activity_DefaultIcon] as ImageSource; public ImageSource? Activity_DefaultIcon => this[ThemeKeys.Activity_DefaultIcon] as ImageSource;
public ImageSource? InfoIcon_None => this[ThemeKeys.InfoIcon_None] as ImageSource;
public ImageSource? InfoIcon_Info => this[ThemeKeys.InfoIcon_Info] as ImageSource;
public ImageSource? InfoIcon_Warning => this[ThemeKeys.InfoIcon_Warning] as ImageSource;
public ImageSource? InfoIcon_Error => this[ThemeKeys.InfoIcon_Error] as ImageSource;
} }
} }

View File

@@ -5,6 +5,18 @@
<DrawingImage x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=Activity_DefaultIcon}"> <DrawingImage x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=Activity_DefaultIcon}">
<!--矢量图标定义--> <!--矢量图标定义-->
</DrawingImage> </DrawingImage>
<DrawingImage x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=InfoIcon_None}">
<!--矢量图标定义-->
</DrawingImage>
<DrawingImage x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=InfoIcon_Info}">
<!--矢量图标定义-->
</DrawingImage>
<DrawingImage x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=InfoIcon_Warning}">
<!--矢量图标定义-->
</DrawingImage>
<DrawingImage x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=InfoIcon_Error}">
<!--矢量图标定义-->
</DrawingImage>
<!-- x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=ResourceKey}" --> <!-- x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=ResourceKey}" -->
</ResourceDictionary> </ResourceDictionary>