-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use BindingOperations.DoNothing if Data is null
- Loading branch information
Showing
3 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/IconPacks.Avalonia.Core/Converter/NullToDoNothingValueConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Avalonia.Data; | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace IconPacks.Avalonia.Converter | ||
{ | ||
public class NullToDoNothingValueConverter : MarkupConverter | ||
{ | ||
// Explicit static constructor to tell C# compiler | ||
// not to mark type as beforefieldinit | ||
static NullToDoNothingValueConverter() | ||
{ | ||
} | ||
|
||
public NullToDoNothingValueConverter() | ||
{ | ||
} | ||
|
||
public static NullToDoNothingValueConverter Instance { get; } = new(); | ||
|
||
/// <inheritdoc /> | ||
public override object ProvideValue(IServiceProvider serviceProvider) | ||
{ | ||
return Instance; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return value ?? BindingOperations.DoNothing; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return BindingOperations.DoNothing; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters