From 4268d1b9b8097f43731677254454002552c33e56 Mon Sep 17 00:00:00 2001 From: Justin Swanson Date: Sat, 16 Nov 2019 23:31:54 -0600 Subject: [PATCH] DetailImageView hides shadows for empty items --- Wabbajack/Views/Common/DetailImageView.xaml | 22 ++++++++----- .../Views/Common/DetailImageView.xaml.cs | 33 ++++++++++++++++--- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/Wabbajack/Views/Common/DetailImageView.xaml b/Wabbajack/Views/Common/DetailImageView.xaml index c5e8a526..38280b2c 100644 --- a/Wabbajack/Views/Common/DetailImageView.xaml +++ b/Wabbajack/Views/Common/DetailImageView.xaml @@ -1,4 +1,4 @@ - + TextWrapping="WrapWithOverflow" + Visibility="{Binding ShowTitle, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource bool2VisibilityHiddenConverter}}"> @@ -113,7 +114,8 @@ FontSize="30" FontWeight="Bold" Style="{StaticResource BackgroundBlurStyle}" - TextWrapping="WrapWithOverflow"> + TextWrapping="WrapWithOverflow" + Visibility="{Binding ShowAuthor, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource bool2VisibilityHiddenConverter}}"> @@ -130,7 +132,8 @@ FontSize="65" FontWeight="Bold" Text="{Binding Title, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" - TextWrapping="WrapWithOverflow"> + TextWrapping="WrapWithOverflow" + Visibility="{Binding ShowTitle, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource bool2VisibilityHiddenConverter}}"> @@ -142,7 +145,8 @@ FontFamily="Lucida Sans" FontSize="30" FontWeight="Bold" - TextWrapping="Wrap"> + TextWrapping="Wrap" + Visibility="{Binding ShowAuthor, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource bool2VisibilityHiddenConverter}}"> @@ -163,7 +167,8 @@ Style="{StaticResource BackgroundBlurStyle}" Text="{Binding Description, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" TextAlignment="Right" - TextWrapping="Wrap"> + TextWrapping="Wrap" + Visibility="{Binding ShowDescription, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource bool2VisibilityHiddenConverter}}"> @@ -179,7 +184,8 @@ FontSize="16" Text="{Binding Description, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" TextAlignment="Right" - TextWrapping="Wrap"> + TextWrapping="Wrap" + Visibility="{Binding ShowDescription, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource bool2VisibilityHiddenConverter}}"> @@ -192,4 +198,4 @@ Grid.ColumnSpan="2" Fill="Transparent" /> - + diff --git a/Wabbajack/Views/Common/DetailImageView.xaml.cs b/Wabbajack/Views/Common/DetailImageView.xaml.cs index e1094ede..4e8c2d9e 100644 --- a/Wabbajack/Views/Common/DetailImageView.xaml.cs +++ b/Wabbajack/Views/Common/DetailImageView.xaml.cs @@ -1,6 +1,8 @@ -using System; +using ReactiveUI; +using System; using System.Collections.Generic; using System.Linq; +using System.Reactive.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -18,7 +20,7 @@ namespace Wabbajack /// /// Interaction logic for DetailImageView.xaml /// - public partial class DetailImageView : UserControl + public partial class DetailImageView : UserControlRx { public ImageSource Image { @@ -42,7 +44,7 @@ namespace Wabbajack set => SetValue(TitleProperty, value); } public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(nameof(Title), typeof(string), typeof(DetailImageView), - new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); + new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, WireNotifyPropertyChanged)); public string Author { @@ -50,7 +52,7 @@ namespace Wabbajack set => SetValue(AuthorProperty, value); } public static readonly DependencyProperty AuthorProperty = DependencyProperty.Register(nameof(Author), typeof(string), typeof(DetailImageView), - new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); + new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, WireNotifyPropertyChanged)); public string Description { @@ -58,11 +60,32 @@ namespace Wabbajack set => SetValue(DescriptionProperty, value); } public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(nameof(Description), typeof(string), typeof(DetailImageView), - new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); + new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, WireNotifyPropertyChanged)); + + private readonly ObservableAsPropertyHelper _ShowAuthor; + public bool ShowAuthor => _ShowAuthor.Value; + + private readonly ObservableAsPropertyHelper _ShowDescription; + public bool ShowDescription => _ShowDescription.Value; + + private readonly ObservableAsPropertyHelper _ShowTitle; + public bool ShowTitle => _ShowTitle.Value; public DetailImageView() { InitializeComponent(); + + this._ShowAuthor = this.WhenAny(x => x.Author) + .Select(x => !string.IsNullOrWhiteSpace(x)) + .ToProperty(this, nameof(this.ShowAuthor)); + + this._ShowDescription = this.WhenAny(x => x.Description) + .Select(x => !string.IsNullOrWhiteSpace(x)) + .ToProperty(this, nameof(this.ShowDescription)); + + this._ShowTitle = this.WhenAny(x => x.Title) + .Select(x => !string.IsNullOrWhiteSpace(x)) + .ToProperty(this, nameof(this.ShowTitle)); } } }