37 lines
988 B
C#
37 lines
988 B
C#
|
|
using Avalonia.Data.Converters;
|
|||
|
|
using Plugin.Cowain.Wcs.ViewModels;
|
|||
|
|
using System.Collections.ObjectModel;
|
|||
|
|
using System.Globalization;
|
|||
|
|
using System.Text.Json;
|
|||
|
|
|
|||
|
|
namespace Plugin.Cowain.Wcs.Converters;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// List和string转换器
|
|||
|
|
/// </summary>
|
|||
|
|
public class ActionStringConverter : IValueConverter
|
|||
|
|
{
|
|||
|
|
public ActionStringConverter()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public object? Convert(object? value, Type targetType, object? prefix, CultureInfo culture)
|
|||
|
|
{
|
|||
|
|
if (value is ObservableCollection<ProcessActionViewModel> lists)
|
|||
|
|
{
|
|||
|
|
return JsonSerializer.Serialize(lists.Select(x => x.Action).ToList());
|
|||
|
|
//return string.Join(',', menuActions);
|
|||
|
|
}
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public object? ConvertBack(object? value, Type targetType, object? prefix, CultureInfo culture)
|
|||
|
|
{
|
|||
|
|
if (value is string jsonString)
|
|||
|
|
{
|
|||
|
|
return JsonSerializer.Deserialize<List<string>>(jsonString);
|
|||
|
|
}
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
}
|