From d6d1d9e134fe7210bcba4ecc05f67d52498f44d4 Mon Sep 17 00:00:00 2001 From: RMBGAME Date: Tue, 23 Nov 2021 12:36:52 +0800 Subject: [PATCH] Fix DonateRecord Avatar --- src/ST.Client.Desktop.Avalonia.App/App.axaml | 2 +- .../EnumDescriptionTypeConverter.cs | 25 ++--- .../Converters/EnumEqualValueConverter.cs | 32 ++++++ .../Views/Pages/About/About_DonatePage.axaml | 102 ++++++++++++------ .../Views/Pages/Settings/Settings_Steam.axaml | 2 +- .../UserProfile/UserProfileWindow.axaml | 4 + 6 files changed, 121 insertions(+), 46 deletions(-) create mode 100644 src/ST.Client.Desktop.Avalonia/Application/Converters/EnumEqualValueConverter.cs diff --git a/src/ST.Client.Desktop.Avalonia.App/App.axaml b/src/ST.Client.Desktop.Avalonia.App/App.axaml index 6e4ec5ec3..355e25194 100644 --- a/src/ST.Client.Desktop.Avalonia.App/App.axaml +++ b/src/ST.Client.Desktop.Avalonia.App/App.axaml @@ -14,9 +14,9 @@ - + diff --git a/src/ST.Client.Desktop.Avalonia/Application/Converters/EnumDescriptionTypeConverter.cs b/src/ST.Client.Desktop.Avalonia/Application/Converters/EnumDescriptionTypeConverter.cs index 6fa1fc116..b2c83367f 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/Converters/EnumDescriptionTypeConverter.cs +++ b/src/ST.Client.Desktop.Avalonia/Application/Converters/EnumDescriptionTypeConverter.cs @@ -1,4 +1,4 @@ -using System.ComponentModel; +using System.ComponentModel; using System.Globalization; using System.Reflection; @@ -10,25 +10,22 @@ namespace System.Application.Converters { } - public override object? ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType) { if (destinationType == typeof(string)) { - if (null != value) + if (value is not null && value is Enum e) { - if (value.GetType().IsEnum) + var fi = e.GetType().GetField(e.ToString()); + + if (null != fi) { - FieldInfo fi = value.GetType().GetField(value.ToString()); + var attributes = + (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); - if (null != fi) - { - var attributes = - (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); - - return ((attributes.Length > 0) && (!string.IsNullOrEmpty(attributes[0].Description))) - ? attributes[0].Description - : value.ToString(); - } + return ((attributes.Length > 0) && (!string.IsNullOrEmpty(attributes[0].Description))) + ? attributes[0].Description + : e.ToString(); } } diff --git a/src/ST.Client.Desktop.Avalonia/Application/Converters/EnumEqualValueConverter.cs b/src/ST.Client.Desktop.Avalonia/Application/Converters/EnumEqualValueConverter.cs new file mode 100644 index 000000000..1f893f4ea --- /dev/null +++ b/src/ST.Client.Desktop.Avalonia/Application/Converters/EnumEqualValueConverter.cs @@ -0,0 +1,32 @@ +using Avalonia.Data; +using Avalonia.Data.Converters; +using System.Globalization; + +namespace System.Application.Converters +{ + public class EnumEqualValueConverter : IValueConverter + { + object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null || parameter == null) + return false; + if (value is Enum) + { + if (parameter is Enum) + { + return value.Equals(parameter); + } + else if (parameter is string) + { + return value.ToString() == parameter.ToString(); + } + } + return false; + } + + object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return BindingOperations.DoNothing; + } + } +} \ No newline at end of file diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/About/About_DonatePage.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/About/About_DonatePage.axaml index dfb875ec4..a2b0afbe1 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/About/About_DonatePage.axaml +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/About/About_DonatePage.axaml @@ -103,36 +103,78 @@ --> - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/Settings/Settings_Steam.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/Settings/Settings_Steam.axaml index 1ee40c555..99006218d 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/Settings/Settings_Steam.axaml +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/Settings/Settings_Steam.axaml @@ -49,7 +49,7 @@ - + diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/UserProfile/UserProfileWindow.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/UserProfile/UserProfileWindow.axaml index f0c5feefc..448ebc627 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/UserProfile/UserProfileWindow.axaml +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/UserProfile/UserProfileWindow.axaml @@ -8,6 +8,7 @@ Width="450" Height="520" MinWidth="450" MinHeight="520" x:Class="System.Application.UI.Views.Windows.UserProfileWindow" + xmlns:converters="using:System.Application.Converters" xmlns:controls="clr-namespace:System.Application.UI.Views.Controls" xmlns:resx="using:System.Application.UI.Resx" xmlns:ccl_services="using:System.Application.Services" @@ -19,6 +20,9 @@ WindowStartupLocation="CenterOwner" x:DataType="vm:UserProfileWindowViewModel" x:CompileBindings="True"> + + +