From 30c6cf668671efa70841c0fb8470867fc7cdac3c Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Thu, 31 Oct 2019 19:54:45 +0200 Subject: [PATCH] Fixes #25 --- Shared/Util/Converters.cs | 10 ++-- Shared/VisualizerControl.xaml | 89 +++++++++++++++++++------------- Shared/VisualizerControl.xaml.cs | 5 +- 3 files changed, 59 insertions(+), 45 deletions(-) diff --git a/Shared/Util/Converters.cs b/Shared/Util/Converters.cs index 36eebe4..6ceebc2 100644 --- a/Shared/Util/Converters.cs +++ b/Shared/Util/Converters.cs @@ -75,13 +75,13 @@ public class NonEmptyListConverter : ReadOnlyMultiConverterBase { public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) => values.OfType>().FirstOrDefault(x => x != null && x.Any()); } - public class HasItemsVisibilityConverter : ReadOnlyConverterBase { - public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) => - (value as IEnumerable).Cast().Any() ? Visibility.Visible : Visibility.Collapsed; - } - public class InvertVisibilityConverter : ReadOnlyConverterBase { public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) => ((Visibility)value) == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible; } + + public class HasValuesVisibilityConverter : ReadOnlyMultiConverterBase { + public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) => + values.All(x => x is string s && !s.IsNullOrWhitespace()) ? Visibility.Visible : Visibility.Hidden; + } } diff --git a/Shared/VisualizerControl.xaml b/Shared/VisualizerControl.xaml index 82146be..ce532f8 100644 --- a/Shared/VisualizerControl.xaml +++ b/Shared/VisualizerControl.xaml @@ -10,8 +10,8 @@ - + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Shared/VisualizerControl.xaml.cs b/Shared/VisualizerControl.xaml.cs index a82d132..855f31a 100644 --- a/Shared/VisualizerControl.xaml.cs +++ b/Shared/VisualizerControl.xaml.cs @@ -69,9 +69,8 @@ public VisualizerControl() { private VisualizerDataViewModel data => (VisualizerDataViewModel)DataContext; private void LoadDataContext() { - if (_objectProvider == null || config == null) { return; } - var response = _objectProvider.TransferObject(config) as VisualizerData; - if (response == null) { + if (_objectProvider is null || config is null) { return; } + if (!(_objectProvider.TransferObject(config) is VisualizerData response)) { throw new InvalidOperationException("Unspecified error while serializing/deserializing"); } DataContext = new VisualizerDataViewModel(response);