Added AbsolutePath converter to stock WPF systems. Added to FilePicker

This commit is contained in:
Justin Swanson 2020-04-01 15:25:22 -05:00 committed by Timothy Baldridge
parent eb2cd8342d
commit 964269de47
5 changed files with 24 additions and 9 deletions

View File

@ -1,11 +1,12 @@
using System;
using System.Globalization;
using System.Windows.Data;
using ReactiveUI;
using Wabbajack.Common;
using Wabbajack.Lib.Downloaders;
namespace Wabbajack.Converters
namespace Wabbajack
{
public class PathToStringConverter : IBindingTypeConverter
public class AbsolutePathToStringConverter : IBindingTypeConverter, IValueConverter
{
public int GetAffinityForObjects(Type fromType, Type toType)
{
@ -14,8 +15,6 @@ namespace Wabbajack.Converters
if (toType == typeof(AbsolutePath)) return 1;
if (toType == typeof(AbsolutePath?)) return 1;
return 0;
}
public bool TryConvert(object @from, Type toType, object conversionHint, out object result)
@ -60,5 +59,21 @@ namespace Wabbajack.Converters
result = default;
return false;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType != typeof(string))
throw new InvalidOperationException($"The target must be of type string");
if (value is AbsolutePath path)
{
return path.ToString();
}
return string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (AbsolutePath)(value as string);
}
}
}

View File

@ -5,7 +5,6 @@ using System.Text;
using System.Threading.Tasks;
using ReactiveUI;
using Splat;
using Wabbajack.Converters;
namespace Wabbajack
{
@ -26,7 +25,7 @@ namespace Wabbajack
typeof(IBindingTypeConverter)
);
Locator.CurrentMutable.RegisterConstant(
new PathToStringConverter(),
new AbsolutePathToStringConverter(),
typeof(IBindingTypeConverter));
}
}

View File

@ -17,6 +17,7 @@
<local:IsNotNullVisibilityConverter x:Key="IsNotNullVisibilityConverter" />
<local:EqualsToBoolConverter x:Key="EqualsToBoolConverter" />
<local:IsTypeVisibilityConverter x:Key="IsTypeVisibilityConverter" />
<local:AbsolutePathToStringConverter x:Key="AbsolutePathToStringConverter" />
<!-- Colors -->
<Color x:Key="WindowBackgroundColor">#121212</Color>

View File

@ -27,7 +27,7 @@
Margin="5,1,-2,1"
VerticalContentAlignment="Center"
Background="{StaticResource DarkBackgroundBrush}"
Text="{Binding PickerVM.TargetPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
Text="{Binding PickerVM.TargetPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource AbsolutePathToStringConverter}}"
Visibility="{Binding PickerVM.ShowTextBoxInput, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
<Grid Grid.Column="1" HorizontalAlignment="Right">
<Border

View File

@ -7,7 +7,7 @@ namespace Wabbajack
/// <summary>
/// Interaction logic for FilePicker.xaml
/// </summary>
public partial class FilePicker : UserControl
public partial class FilePicker
{
// This exists, as utilizing the datacontext directly seemed to bug out the exit animations
// "Bouncing" off this property seems to fix it, though. Could perhaps be done other ways.