You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.9 KiB
63 lines
1.9 KiB
|
1 month ago
|
using System;
|
||
|
|
using System.Globalization;
|
||
|
|
using AuroraDesk.Core.Entities;
|
||
|
|
using AuroraDesk.Presentation.ViewModels.Pages;
|
||
|
|
using Avalonia.Data.Converters;
|
||
|
|
using Avalonia.Media;
|
||
|
|
|
||
|
|
namespace AuroraDesk.Presentation.Converters;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 根据 Plink 消息的方向与状态返回不同的背景色
|
||
|
|
/// </summary>
|
||
|
|
public sealed class PlinkMessageBackgroundConverter : IValueConverter
|
||
|
|
{
|
||
|
|
private static readonly SolidColorBrush IncomingBrush = SolidColorBrush.Parse("#DCFCE7");
|
||
|
|
private static readonly SolidColorBrush OutgoingBrush = SolidColorBrush.Parse("#DBEAFE");
|
||
|
|
private static readonly SolidColorBrush ErrorBrush = SolidColorBrush.Parse("#FEE2E2");
|
||
|
|
private static readonly SolidColorBrush SystemBrush = SolidColorBrush.Parse("#F3F4F6");
|
||
|
|
|
||
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||
|
|
{
|
||
|
|
if (value is PlinkMessageEntry entry)
|
||
|
|
{
|
||
|
|
if (entry.IsError)
|
||
|
|
{
|
||
|
|
return ErrorBrush;
|
||
|
|
}
|
||
|
|
|
||
|
|
return entry.Direction switch
|
||
|
|
{
|
||
|
|
PlinkMessageDirection.Incoming => IncomingBrush,
|
||
|
|
PlinkMessageDirection.Outgoing => OutgoingBrush,
|
||
|
|
PlinkMessageDirection.System => SystemBrush,
|
||
|
|
_ => SystemBrush
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
if (value is PlinkMessage message)
|
||
|
|
{
|
||
|
|
if (message.IsError)
|
||
|
|
{
|
||
|
|
return ErrorBrush;
|
||
|
|
}
|
||
|
|
|
||
|
|
return message.Direction switch
|
||
|
|
{
|
||
|
|
PlinkMessageDirection.Incoming => IncomingBrush,
|
||
|
|
PlinkMessageDirection.Outgoing => OutgoingBrush,
|
||
|
|
PlinkMessageDirection.System => SystemBrush,
|
||
|
|
_ => SystemBrush
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
return SystemBrush;
|
||
|
|
}
|
||
|
|
|
||
|
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||
|
|
{
|
||
|
|
throw new NotSupportedException();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|