Swapped DetailImageView to RxUI bindings

This commit is contained in:
Justin Swanson 2020-05-12 19:31:04 -05:00
parent 03afaceadc
commit 799c7e2090
2 changed files with 72 additions and 46 deletions

View File

@ -43,9 +43,6 @@
</BeginStoryboard> </BeginStoryboard>
</DataTrigger.ExitActions> </DataTrigger.ExitActions>
</DataTrigger> </DataTrigger>
<DataTrigger Binding="{Binding Image}" Value="{x:Null}">
<Setter Property="Visibility" Value="Hidden" />
</DataTrigger>
</Style.Triggers> </Style.Triggers>
</Style> </Style>
</UserControl.Resources> </UserControl.Resources>
@ -74,9 +71,9 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
Stretch="UniformToFill"> Stretch="UniformToFill">
<Image Source="{Binding Image, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" /> <Image x:Name="ModlistImage" />
</Viewbox> </Viewbox>
<Image <Image x:Name="BadgeImage"
Grid.Row="0" Grid.Row="0"
Grid.RowSpan="4" Grid.RowSpan="4"
Grid.Column="0" Grid.Column="0"
@ -84,8 +81,7 @@
Width="60" Width="60"
Height="60" Height="60"
HorizontalAlignment="Left" HorizontalAlignment="Left"
VerticalAlignment="Top" VerticalAlignment="Top" />
Source="{Binding Badge, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
<TextBlock <TextBlock
x:Name="TitleTextShadow" x:Name="TitleTextShadow"
Grid.Row="2" Grid.Row="2"
@ -98,15 +94,13 @@
FontSize="65" FontSize="65"
FontWeight="Bold" FontWeight="Bold"
Style="{StaticResource BackgroundBlurStyle}" Style="{StaticResource BackgroundBlurStyle}"
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}}">
<TextBlock.Effect> <TextBlock.Effect>
<BlurEffect Radius="85" /> <BlurEffect Radius="85" />
</TextBlock.Effect> </TextBlock.Effect>
</TextBlock> </TextBlock>
<TextBlock <TextBlock
x:Name="ArtistTextShadow" x:Name="AuthorTextShadow"
Grid.Row="3" Grid.Row="3"
Grid.Column="0" Grid.Column="0"
Margin="35,-10,-10,10" Margin="35,-10,-10,10"
@ -116,15 +110,14 @@
FontSize="30" FontSize="30"
FontWeight="Bold" FontWeight="Bold"
Style="{StaticResource BackgroundBlurStyle}" Style="{StaticResource BackgroundBlurStyle}"
TextWrapping="WrapWithOverflow" TextWrapping="WrapWithOverflow">
Visibility="{Binding ShowAuthor, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource bool2VisibilityHiddenConverter}}">
<TextBlock.Effect> <TextBlock.Effect>
<BlurEffect Radius="55" /> <BlurEffect Radius="55" />
</TextBlock.Effect> </TextBlock.Effect>
<Run FontSize="15" Text="by" /> <Run FontSize="15" Text="by" />
<Run Text="{Binding Author, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" /> <Run x:Name="AuthorShadowTextRun" />
</TextBlock> </TextBlock>
<TextBlock <TextBlock x:Name="TitleTextBlock"
Grid.Row="2" Grid.Row="2"
Grid.Column="0" Grid.Column="0"
Margin="20,25,20,0" Margin="20,25,20,0"
@ -133,27 +126,24 @@
FontFamily="Lucida Sans" FontFamily="Lucida Sans"
FontSize="65" FontSize="65"
FontWeight="Bold" 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}}">
<TextBlock.Effect> <TextBlock.Effect>
<DropShadowEffect /> <DropShadowEffect />
</TextBlock.Effect> </TextBlock.Effect>
</TextBlock> </TextBlock>
<TextBlock <TextBlock x:Name="AuthorTextBlock"
Grid.Row="3" Grid.Row="3"
Grid.Column="0" Grid.Column="0"
Margin="55,0,20,20" Margin="55,0,20,20"
FontFamily="Lucida Sans" FontFamily="Lucida Sans"
FontSize="30" FontSize="30"
FontWeight="Bold" FontWeight="Bold"
TextWrapping="Wrap" TextWrapping="Wrap">
Visibility="{Binding ShowAuthor, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource bool2VisibilityHiddenConverter}}">
<TextBlock.Effect> <TextBlock.Effect>
<DropShadowEffect /> <DropShadowEffect />
</TextBlock.Effect> </TextBlock.Effect>
<Run FontSize="15" Text="by" /> <Run FontSize="15" Text="by" />
<Run Text="{Binding Author, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" /> <Run x:Name="AuthorTextRun" />
</TextBlock> </TextBlock>
<TextBlock <TextBlock
x:Name="DescriptionTextShadow" x:Name="DescriptionTextShadow"
@ -167,15 +157,13 @@
FontFamily="Lucida Sans" FontFamily="Lucida Sans"
FontSize="16" FontSize="16"
Style="{StaticResource BackgroundBlurStyle}" Style="{StaticResource BackgroundBlurStyle}"
Text="{Binding Description, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
TextAlignment="Right" TextAlignment="Right"
TextWrapping="Wrap" TextWrapping="Wrap">
Visibility="{Binding ShowDescription, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource bool2VisibilityHiddenConverter}}">
<TextBlock.Effect> <TextBlock.Effect>
<BlurEffect Radius="55" /> <BlurEffect Radius="55" />
</TextBlock.Effect> </TextBlock.Effect>
</TextBlock> </TextBlock>
<TextBlock <TextBlock x:Name="DescriptionTextBlock"
Grid.Row="2" Grid.Row="2"
Grid.RowSpan="2" Grid.RowSpan="2"
Grid.Column="1" Grid.Column="1"
@ -184,10 +172,8 @@
VerticalAlignment="Bottom" VerticalAlignment="Bottom"
FontFamily="Lucida Sans" FontFamily="Lucida Sans"
FontSize="16" FontSize="16"
Text="{Binding Description, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
TextAlignment="Right" TextAlignment="Right"
TextWrapping="Wrap" TextWrapping="Wrap">
Visibility="{Binding ShowDescription, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource bool2VisibilityHiddenConverter}}">
<TextBlock.Effect> <TextBlock.Effect>
<DropShadowEffect /> <DropShadowEffect />
</TextBlock.Effect> </TextBlock.Effect>

View File

@ -22,7 +22,7 @@ namespace Wabbajack
set => SetValue(ImageProperty, value); set => SetValue(ImageProperty, value);
} }
public static readonly DependencyProperty ImageProperty = DependencyProperty.Register(nameof(Image), typeof(ImageSource), typeof(DetailImageView), public static readonly DependencyProperty ImageProperty = DependencyProperty.Register(nameof(Image), typeof(ImageSource), typeof(DetailImageView),
new FrameworkPropertyMetadata(default(ImageSource))); new FrameworkPropertyMetadata(default(ImageSource), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, WireNotifyPropertyChanged));
public ImageSource Badge public ImageSource Badge
{ {
@ -30,7 +30,7 @@ namespace Wabbajack
set => SetValue(BadgeProperty, value); set => SetValue(BadgeProperty, value);
} }
public static readonly DependencyProperty BadgeProperty = DependencyProperty.Register(nameof(Badge), typeof(ImageSource), typeof(DetailImageView), public static readonly DependencyProperty BadgeProperty = DependencyProperty.Register(nameof(Badge), typeof(ImageSource), typeof(DetailImageView),
new FrameworkPropertyMetadata(default(ImageSource))); new FrameworkPropertyMetadata(default(ImageSource), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, WireNotifyPropertyChanged));
public string Title public string Title
{ {
@ -56,34 +56,74 @@ namespace Wabbajack
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(nameof(Description), typeof(string), typeof(DetailImageView), public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(nameof(Description), typeof(string), typeof(DetailImageView),
new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, WireNotifyPropertyChanged)); new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, WireNotifyPropertyChanged));
[Reactive]
public bool ShowAuthor { get; private set; }
[Reactive]
public bool ShowDescription { get; private set; }
[Reactive]
public bool ShowTitle { get; private set; }
public DetailImageView() public DetailImageView()
{ {
InitializeComponent(); InitializeComponent();
this.WhenActivated(dispose => this.WhenActivated(dispose =>
{ {
// Update textboxes
var authorVisible = this.WhenAny(x => x.Author)
.Select(x => string.IsNullOrWhiteSpace(x) ? Visibility.Collapsed : Visibility.Visible)
.Replay(1)
.RefCount();
authorVisible
.BindToStrict(this, x => x.AuthorTextBlock.Visibility)
.DisposeWith(dispose);
authorVisible
.BindToStrict(this, x => x.AuthorTextShadow.Visibility)
.DisposeWith(dispose);
this.WhenAny(x => x.Author) this.WhenAny(x => x.Author)
.Select(x => !string.IsNullOrWhiteSpace(x)) .BindToStrict(this, x => x.AuthorTextRun.Text)
.Subscribe(x => ShowAuthor = x) .DisposeWith(dispose);
this.WhenAny(x => x.Author)
.BindToStrict(this, x => x.AuthorShadowTextRun.Text)
.DisposeWith(dispose); .DisposeWith(dispose);
var descVisible = this.WhenAny(x => x.Description)
.Select(x => string.IsNullOrWhiteSpace(x) ? Visibility.Collapsed : Visibility.Visible)
.Replay(1)
.RefCount();
descVisible
.BindToStrict(this, x => x.DescriptionTextBlock.Visibility)
.DisposeWith(dispose);
descVisible
.BindToStrict(this, x => x.DescriptionTextShadow.Visibility)
.DisposeWith(dispose);
this.WhenAny(x => x.Description) this.WhenAny(x => x.Description)
.Select(x => !string.IsNullOrWhiteSpace(x)) .BindToStrict(this, x => x.DescriptionTextBlock.Text)
.Subscribe(x => ShowDescription = x) .DisposeWith(dispose);
this.WhenAny(x => x.Description)
.BindToStrict(this, x => x.DescriptionTextShadow.Text)
.DisposeWith(dispose); .DisposeWith(dispose);
var titleVisible = this.WhenAny(x => x.Title)
.Select(x => string.IsNullOrWhiteSpace(x) ? Visibility.Collapsed : Visibility.Visible)
.Replay(1)
.RefCount();
titleVisible
.BindToStrict(this, x => x.TitleTextBlock.Visibility)
.DisposeWith(dispose);
titleVisible
.BindToStrict(this, x => x.TitleTextShadow.Visibility)
.DisposeWith(dispose);
this.WhenAny(x => x.Title) this.WhenAny(x => x.Title)
.Select(x => !string.IsNullOrWhiteSpace(x)) .BindToStrict(this, x => x.TitleTextBlock.Text)
.Subscribe(x => ShowTitle = x) .DisposeWith(dispose);
this.WhenAny(x => x.Title)
.BindToStrict(this, x => x.TitleTextShadow.Text)
.DisposeWith(dispose);
// Update other items
this.WhenAny(x => x.Badge)
.BindToStrict(this, x => x.BadgeImage.Source)
.DisposeWith(dispose);
this.WhenAny(x => x.Image)
.BindToStrict(this, x => x.ModlistImage.Source)
.DisposeWith(dispose);
this.WhenAny(x => x.Image)
.Select(img => img == null ? Visibility.Hidden : Visibility.Visible)
.BindToStrict(this, x => x.Visibility)
.DisposeWith(dispose); .DisposeWith(dispose);
}); });
} }