Fixed some minor ui things with constraints
This commit is contained in:
parent
14bad15f4a
commit
eacfcf611c
@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Globalization;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
|
|
||||||
|
namespace XSDVisualiser.Desktop.Converters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the bound value is a collection with at least one item. Supports IEnumerable and ICollection.
|
||||||
|
/// Optional parameter "Invert" to invert the boolean result.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class CollectionHasItemsConverter : IValueConverter
|
||||||
|
{
|
||||||
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
var hasItems = false;
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case ICollection coll:
|
||||||
|
hasItems = coll.Count > 0;
|
||||||
|
break;
|
||||||
|
case IEnumerable enumerable:
|
||||||
|
{
|
||||||
|
var enumerator = enumerable.GetEnumerator();
|
||||||
|
hasItems = enumerator.MoveNext();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var invert = parameter is string s && s.Equals("Invert", StringComparison.OrdinalIgnoreCase);
|
||||||
|
return invert ? !hasItems : hasItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
=> throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,6 +9,7 @@
|
|||||||
<conv:CardinalityToLabelConverter x:Key="CardinalityToLabel"/>
|
<conv:CardinalityToLabelConverter x:Key="CardinalityToLabel"/>
|
||||||
<conv:OptionalToBorderBrushConverter x:Key="OptionalToBrush"/>
|
<conv:OptionalToBorderBrushConverter x:Key="OptionalToBrush"/>
|
||||||
<conv:OptionalToThicknessConverter x:Key="OptionalToThickness"/>
|
<conv:OptionalToThicknessConverter x:Key="OptionalToThickness"/>
|
||||||
|
<conv:CollectionHasItemsConverter x:Key="HasItems"/>
|
||||||
</Window.Resources>
|
</Window.Resources>
|
||||||
|
|
||||||
<Grid RowDefinitions="Auto,*" Margin="12">
|
<Grid RowDefinitions="Auto,*" Margin="12">
|
||||||
@ -129,7 +130,7 @@
|
|||||||
|
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<TextBlock Text="Enumerations" FontWeight="SemiBold"/>
|
<TextBlock Text="Enumerations" FontWeight="SemiBold"/>
|
||||||
<ItemsControl ItemsSource="{Binding Enumerations}">
|
<ItemsControl ItemsSource="{Binding Enumerations}" IsVisible="{Binding Enumerations, Converter={StaticResource HasItems}}">
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<DataTemplate x:DataType="x:String">
|
<DataTemplate x:DataType="x:String">
|
||||||
<TextBlock Text="{Binding ., StringFormat=• {0}}"/>
|
<TextBlock Text="{Binding ., StringFormat=• {0}}"/>
|
||||||
@ -140,7 +141,7 @@
|
|||||||
|
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<TextBlock Text="Patterns" FontWeight="SemiBold"/>
|
<TextBlock Text="Patterns" FontWeight="SemiBold"/>
|
||||||
<ItemsControl ItemsSource="{Binding Patterns}">
|
<ItemsControl ItemsSource="{Binding Patterns}" IsVisible="{Binding Patterns, Converter={StaticResource HasItems}}">
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<DataTemplate x:DataType="x:String">
|
<DataTemplate x:DataType="x:String">
|
||||||
<TextBlock Text="{Binding ., StringFormat=• {0}}"/>
|
<TextBlock Text="{Binding ., StringFormat=• {0}}"/>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user