using Microsoft.UI.Xaml.Data; using XFEExtension.NetCore.StringExtension; namespace XFEExtension.NetCore.WinUIHelper.Utilities.Converter; /// /// Provides conversion logic for handling empty strings in data binding scenarios. /// /// This converter transforms empty or null string values into a predefined placeholder string ("无") and /// vice versa. It is commonly used in UI applications to display a user-friendly representation of empty /// strings. public partial class EmptyStringConverter : IValueConverter { /// /// Converts the specified value to a target type, returning a default representation if the value is null or empty. /// /// The value to be converted. If the value is null or an empty string, a default representation is returned. /// The type to which the value is being converted. This parameter is not used in the current implementation. /// An optional parameter that can be used to influence the conversion logic. This parameter is not used in the /// current implementation. /// The language information for the conversion. This parameter is not used in the current implementation. /// The original value if it is not null or empty; otherwise, the string "无". public object Convert(object value, Type targetType, object parameter, string language) => value.ToString().IsNullOrEmpty() ? "无" : value; /// /// Converts a value back to its original representation based on the specified logic. /// /// The value to be converted back. Typically a string representation. /// The type to which the value is being converted. This parameter is not used in the current implementation. /// An optional parameter for the conversion logic. This parameter is not used in the current implementation. /// The language information for the conversion. This parameter is not used in the current implementation. /// A string representing the converted value. Returns an empty string if the input value is "无"; otherwise, returns /// the original value. public object ConvertBack(object value, Type targetType, object parameter, string language) => value.ToString() == "无" ? string.Empty : value; }