Created
January 5, 2023 01:18
-
-
Save emoacht/5dbe8bad43fdf67076ec28433f3cf4fe to your computer and use it in GitHub Desktop.
Converts the state whether the source object is a collection and it has any item to boolean.
This file contains hidden or 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
using System; | |
using System.Collections; | |
using System.Globalization; | |
using System.Windows.Data; | |
public class CollectionToBooleanConverter : IValueConverter | |
{ | |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
if (value is IEnumerable collection) | |
{ | |
foreach (var _ in collection) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
throw new NotSupportedException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This converter should work but in practice, there is almost no use because it will be called only when the source collection is set or replaced.