-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUlongToStringConverter.cs
More file actions
31 lines (26 loc) · 937 Bytes
/
Copy pathUlongToStringConverter.cs
File metadata and controls
31 lines (26 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System.Globalization;
using System.Windows.Data;
namespace GView;
/* Used
* https://learn.microsoft.com/en-us/dotnet/desktop/wpf/data/how-to-convert-bound-data?view=netframeworkdesktop-4.8
*/
[ValueConversion(typeof(ulong), typeof(string))]
public class UlongToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not ulong)
return value;
return ((ulong) value == 0
? string.Empty
: value.ToString())
?? string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not string || ReferenceEquals(value, string.Empty))
return value;
string? str = value.ToString();
return str != null ? ulong.Parse(str) : value;
}
}