Fixed obscure FilePicker bug

The exit animations on errors were not firing if the datacontext was what changed.  Adding a middleman property fixed the issue.  Probably a bit hacky
This commit is contained in:
Justin Swanson
2019-12-15 00:20:28 -06:00
parent 705914bd77
commit e388c018dc
7 changed files with 33 additions and 20 deletions

View File

@ -27,20 +27,20 @@
Margin="5,1,-2,1" Margin="5,1,-2,1"
VerticalContentAlignment="Center" VerticalContentAlignment="Center"
Background="{StaticResource DarkBackgroundBrush}" Background="{StaticResource DarkBackgroundBrush}"
Text="{Binding TargetPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Text="{Binding PickerVM.TargetPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
Visibility="{Binding ShowTextBoxInput}" /> Visibility="{Binding PickerVM.ShowTextBoxInput, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
<Grid Grid.Column="1" HorizontalAlignment="Right"> <Grid Grid.Column="1" HorizontalAlignment="Right">
<Border <Border
Margin="3,1,0,1" Margin="3,1,0,1"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Background="{StaticResource WarningBrush}" Background="{StaticResource WarningBrush}"
CornerRadius="3" CornerRadius="3"
ToolTip="{Binding ErrorTooltip}"> ToolTip="{Binding PickerVM.ErrorTooltip, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}">
<Border.Style> <Border.Style>
<Style TargetType="Border"> <Style TargetType="Border">
<Setter Property="Width" Value="25" /> <Setter Property="Width" Value="25" />
<Style.Triggers> <Style.Triggers>
<DataTrigger Binding="{Binding InError}" Value="True"> <DataTrigger Binding="{Binding PickerVM.InError, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Value="True">
<DataTrigger.EnterActions> <DataTrigger.EnterActions>
<BeginStoryboard> <BeginStoryboard>
<Storyboard> <Storyboard>
@ -79,7 +79,7 @@
HorizontalAlignment="Left" HorizontalAlignment="Left"
Background="{StaticResource TextBoxBackground}" Background="{StaticResource TextBoxBackground}"
CornerRadius="3"> CornerRadius="3">
<Button Command="{Binding SetTargetPathCommand}" ToolTip="Set target path"> <Button Command="{Binding PickerVM.SetTargetPathCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" ToolTip="Set target path">
<icon:PackIconMaterial <icon:PackIconMaterial
Width="16" Width="16"
Height="12" Height="12"

View File

@ -1,4 +1,7 @@
using System.Windows.Controls; using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Wabbajack.Lib;
namespace Wabbajack namespace Wabbajack
{ {
@ -7,6 +10,16 @@ namespace Wabbajack
/// </summary> /// </summary>
public partial class FilePicker : UserControl public partial class FilePicker : UserControl
{ {
// 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.
public FilePickerVM PickerVM
{
get => (FilePickerVM)GetValue(PickerVMProperty);
set => SetValue(PickerVMProperty, value);
}
public static readonly DependencyProperty PickerVMProperty = DependencyProperty.Register(nameof(PickerVM), typeof(FilePickerVM), typeof(FilePicker),
new FrameworkPropertyMetadata(default(FilePickerVM)));
public FilePicker() public FilePicker()
{ {
InitializeComponent(); InitializeComponent();

View File

@ -143,7 +143,7 @@
TextWrapping="Wrap" /> TextWrapping="Wrap" />
<TextBlock Margin="{StaticResource TitleMargin}" Text="Image" /> <TextBlock Margin="{StaticResource TitleMargin}" Text="Image" />
<local:FilePicker <local:FilePicker
DataContext="{Binding ImagePath}" PickerVM="{Binding ImagePath}"
Style="{StaticResource PickerStyle}" Style="{StaticResource PickerStyle}"
ToolTip="Path to an image to display for the modlist." /> ToolTip="Path to an image to display for the modlist." />
<TextBlock Margin="{StaticResource TitleMargin}" Text="Website" /> <TextBlock Margin="{StaticResource TitleMargin}" Text="Website" />
@ -153,7 +153,7 @@
Text="Readme Path" Text="Readme Path"
ToolTip="Path to a readme file." /> ToolTip="Path to a readme file." />
<local:FilePicker <local:FilePicker
DataContext="{Binding ReadMeText}" PickerVM="{Binding ReadMeText}"
Style="{StaticResource PickerStyle}" Style="{StaticResource PickerStyle}"
ToolTip="Path to a readme file." /> ToolTip="Path to a readme file." />
</StackPanel> </StackPanel>

View File

@ -34,7 +34,7 @@
Grid.Column="2" Grid.Column="2"
Height="30" Height="30"
VerticalAlignment="Center" VerticalAlignment="Center"
DataContext="{Binding ModListLocation}" PickerVM="{Binding ModListLocation}"
FontSize="14" FontSize="14"
ToolTip="The MO2 modlist.txt file you want to use as your source" /> ToolTip="The MO2 modlist.txt file you want to use as your source" />
<TextBlock <TextBlock
@ -51,7 +51,7 @@
Grid.Column="2" Grid.Column="2"
Height="30" Height="30"
VerticalAlignment="Center" VerticalAlignment="Center"
DataContext="{Binding DownloadLocation}" PickerVM="{Binding DownloadLocation}"
FontSize="14" FontSize="14"
ToolTip="The folder where MO2 downloads your mods." /> ToolTip="The folder where MO2 downloads your mods." />
<TextBlock <TextBlock
@ -68,7 +68,7 @@
Grid.Column="2" Grid.Column="2"
Height="30" Height="30"
VerticalAlignment="Center" VerticalAlignment="Center"
DataContext="{Binding Parent.OutputLocation}" PickerVM="{Binding Parent.OutputLocation}"
FontSize="14" FontSize="14"
ToolTip="The folder to place the resulting modlist.wabbajack file" /> ToolTip="The folder to place the resulting modlist.wabbajack file" />
</Grid> </Grid>

View File

@ -63,7 +63,7 @@
Grid.Column="2" Grid.Column="2"
Height="30" Height="30"
VerticalAlignment="Center" VerticalAlignment="Center"
DataContext="{Binding GameLocation}" PickerVM="{Binding GameLocation}"
FontSize="14" FontSize="14"
ToolTip="The install folder for the game" /> ToolTip="The install folder for the game" />
<Grid <Grid
@ -109,7 +109,7 @@
Grid.Column="6" Grid.Column="6"
Height="30" Height="30"
VerticalAlignment="Center" VerticalAlignment="Center"
DataContext="{Binding DownloadsLocation}" PickerVM="{Binding DownloadsLocation}"
FontSize="14" FontSize="14"
ToolTip="The folder to download your mods" /> ToolTip="The folder to download your mods" />
<TextBlock <TextBlock
@ -125,7 +125,7 @@
Grid.Column="6" Grid.Column="6"
Height="30" Height="30"
VerticalAlignment="Center" VerticalAlignment="Center"
DataContext="{Binding StagingLocation}" PickerVM="{Binding StagingLocation}"
FontSize="14" /> FontSize="14" />
<TextBlock <TextBlock
Grid.Row="2" Grid.Row="2"
@ -141,7 +141,7 @@
Grid.Column="6" Grid.Column="6"
Height="30" Height="30"
VerticalAlignment="Center" VerticalAlignment="Center"
DataContext="{Binding Parent.OutputLocation}" PickerVM="{Binding Parent.OutputLocation}"
FontSize="14" FontSize="14"
ToolTip="The folder to place the resulting modlist.wabbajack file" /> ToolTip="The folder to place the resulting modlist.wabbajack file" />
</Grid> </Grid>

View File

@ -314,7 +314,7 @@
Grid.Column="2" Grid.Column="2"
Height="30" Height="30"
VerticalAlignment="Center" VerticalAlignment="Center"
DataContext="{Binding ModListLocation}" PickerVM="{Binding ModListLocation}"
FontSize="14" /> FontSize="14" />
<ContentPresenter <ContentPresenter
Grid.Row="3" Grid.Row="3"

View File

@ -33,8 +33,8 @@
Grid.Column="2" Grid.Column="2"
Height="30" Height="30"
VerticalAlignment="Center" VerticalAlignment="Center"
DataContext="{Binding Location}" FontSize="14"
FontSize="14" /> PickerVM="{Binding Location}" />
<TextBlock <TextBlock
Grid.Row="1" Grid.Row="1"
Grid.Column="0" Grid.Column="0"
@ -48,8 +48,8 @@
Grid.Column="2" Grid.Column="2"
Height="30" Height="30"
VerticalAlignment="Center" VerticalAlignment="Center"
DataContext="{Binding DownloadLocation}" FontSize="14"
FontSize="14" /> PickerVM="{Binding DownloadLocation}" />
<CheckBox <CheckBox
Grid.Row="2" Grid.Row="2"
Grid.Column="2" Grid.Column="2"