From 964269de475df1cb069161a139c945a41971f58c Mon Sep 17 00:00:00 2001 From: Justin Swanson Date: Wed, 1 Apr 2020 15:25:22 -0500 Subject: [PATCH] Added AbsolutePath converter to stock WPF systems. Added to FilePicker --- ...er.cs => AbsolutePathToStringConverter.cs} | 25 +++++++++++++++---- Wabbajack/Converters/ConverterRegistration.cs | 3 +-- Wabbajack/Themes/Styles.xaml | 1 + Wabbajack/Views/Common/FilePicker.xaml | 2 +- Wabbajack/Views/Common/FilePicker.xaml.cs | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) rename Wabbajack/Converters/{PathToStringConverter.cs => AbsolutePathToStringConverter.cs} (68%) diff --git a/Wabbajack/Converters/PathToStringConverter.cs b/Wabbajack/Converters/AbsolutePathToStringConverter.cs similarity index 68% rename from Wabbajack/Converters/PathToStringConverter.cs rename to Wabbajack/Converters/AbsolutePathToStringConverter.cs index 856c3447..39aae18d 100644 --- a/Wabbajack/Converters/PathToStringConverter.cs +++ b/Wabbajack/Converters/AbsolutePathToStringConverter.cs @@ -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); + } } } diff --git a/Wabbajack/Converters/ConverterRegistration.cs b/Wabbajack/Converters/ConverterRegistration.cs index e8efc2b2..2c961991 100644 --- a/Wabbajack/Converters/ConverterRegistration.cs +++ b/Wabbajack/Converters/ConverterRegistration.cs @@ -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)); } } diff --git a/Wabbajack/Themes/Styles.xaml b/Wabbajack/Themes/Styles.xaml index 54b648e4..16648754 100644 --- a/Wabbajack/Themes/Styles.xaml +++ b/Wabbajack/Themes/Styles.xaml @@ -17,6 +17,7 @@ + #121212 diff --git a/Wabbajack/Views/Common/FilePicker.xaml b/Wabbajack/Views/Common/FilePicker.xaml index 11e5b0dd..0a8a2620 100644 --- a/Wabbajack/Views/Common/FilePicker.xaml +++ b/Wabbajack/Views/Common/FilePicker.xaml @@ -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}}}" /> /// Interaction logic for FilePicker.xaml /// - 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.