Removed ShowReportButton property in favor of IsNotNullVisibilityConverter

This commit is contained in:
Justin Swanson 2019-10-12 14:11:52 -05:00
parent d6295cc306
commit b24a2a5ce4
5 changed files with 52 additions and 16 deletions

View File

@ -66,6 +66,9 @@ namespace Wabbajack
private bool _UIReady;
public bool UIReady { get => _UIReady; set => this.RaiseAndSetIfChanged(ref _UIReady, value); }
private string _HTMLReport;
public string HTMLReport { get => _HTMLReport; set => this.RaiseAndSetIfChanged(ref _HTMLReport, value); }
// Command properties
public IReactiveCommand ChangePathCommand => ReactiveCommand.Create(ExecuteChangePath);
public IReactiveCommand ChangeDownloadPathCommand => ReactiveCommand.Create(ExecuteChangeDownloadPath);
@ -76,6 +79,10 @@ namespace Wabbajack
public IReactiveCommand OpenModListPropertiesCommand => ReactiveCommand.Create(OpenModListProperties);
public IReactiveCommand SlideShowNextItemCommand { get; }
public AppState()
{
}
public AppState(TaskMode mode)
{
if (Assembly.GetEntryAssembly().Location.ToLower().Contains("\\downloads\\"))
@ -207,20 +214,6 @@ namespace Wabbajack
private string _DownloadLocation;
public string DownloadLocation { get => _DownloadLocation; set => this.RaiseAndSetIfChanged(ref _DownloadLocation, value); }
public Visibility ShowReportButton => _htmlReport == null ? Visibility.Collapsed : Visibility.Visible;
private string _htmlReport;
public string HTMLReport
{
get => _htmlReport;
set
{
_htmlReport = value;
this.RaisePropertyChanged();
this.RaisePropertyChanged(nameof(ShowReportButton));
}
}
private int _queueProgress;
public int QueueProgress { get => _queueProgress; set => this.RaiseAndSetIfChanged(ref _queueProgress, value); }

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace Wabbajack
{
/// <summary>
/// Evaluates any object and converts it to a visibility based on if it is null.
/// By default it will show if the object is not null, and collapse when it is null.
/// If ConverterParameter is set to false, then this behavior is inverted
/// </summary>
public class IsNotNullVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType != typeof(Visibility))
throw new InvalidOperationException($"The target must be of type {nameof(Visibility)}");
bool compareTo = true;
if (parameter is bool p)
{
compareTo = p;
}
else if (parameter is string str && str.ToUpper().Equals("FALSE"))
{
compareTo = false;
}
return value != null ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@ -2,11 +2,13 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Wabbajack"
xmlns:darkBlendTheme="clr-namespace:DarkBlendTheme"
mc:Ignorable="d">
<!--Converters-->
<BooleanToVisibilityConverter x:Key="bool2VisibilityConverter"/>
<local:IsNotNullVisibilityConverter x:Key="IsNotNullVisibilityConverter"/>
<!--Colors-->
<Color x:Key="WindowBackgroundColor">#444444</Color>

View File

@ -309,7 +309,7 @@
Grid.Row="0"
Margin="0,0,0,4"
Command="{Binding ShowReportCommand}"
Visibility="{Binding ShowReportButton}">
Visibility="{Binding HTMLReport, Converter={StaticResource IsNotNullVisibilityConverter}}">
<TextBlock FontSize="13" FontWeight="Bold">View ModList Contents</TextBlock>
</Button>
<Button

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Costura.Fody.4.0.0\build\Costura.Fody.props" Condition="Exists('..\packages\Costura.Fody.4.0.0\build\Costura.Fody.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
@ -221,6 +221,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Converters\IsNotNullVisibilityConverter.cs" />
<Compile Include="Data.cs" />
<Compile Include="Extensions\ReactiveUIExt.cs" />
<Compile Include="UI\ModlistPropertiesWindow.xaml.cs">