Browse Source
Merge pull request #9725 from DmitryZhelnin/9650-fix-nullable-bool
DataGridValueConverter: fix processing of nullable values
pull/9727/head
Max Katz
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
7 additions and
3 deletions
-
src/Avalonia.Controls.DataGrid/DataGridValueConverter.cs
|
|
|
@ -22,14 +22,18 @@ namespace Avalonia.Controls |
|
|
|
return DefaultValueConverter.Instance.Convert(value, targetType, parameter, culture); |
|
|
|
} |
|
|
|
|
|
|
|
// This suppresses a warning saying that we should use String.IsNullOrEmpty instead of a string
|
|
|
|
// comparison, but in this case we want to explicitly check for Empty and not Null.
|
|
|
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
|
|
|
{ |
|
|
|
if (targetType != null && targetType.IsNullableType()) |
|
|
|
{ |
|
|
|
var strValue = value as string; |
|
|
|
if (string.IsNullOrEmpty(strValue)) |
|
|
|
|
|
|
|
// This suppresses a warning saying that we should use String.IsNullOrEmpty instead of a string
|
|
|
|
// comparison, but in this case we want to explicitly check for Empty and not Null.
|
|
|
|
#pragma warning disable CA1820
|
|
|
|
if (strValue == string.Empty) |
|
|
|
#pragma warning restore CA1820
|
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|