Skip to content

Commit 4b55ae0

Browse files
authored
Fix: Fixed crash when switching away from Git folder (#12656)
1 parent 2fabe0f commit 4b55ae0

File tree

2 files changed

+103
-71
lines changed

2 files changed

+103
-71
lines changed

src/Files.App/Converters/Converters.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,31 @@ protected override string ConvertBack(bool value, object? parameter, string? lan
211211
return string.Empty;
212212
}
213213
}
214+
215+
internal sealed class NullToVisibilityCollapsedConverter : ValueConverter<object?, Visibility>
216+
{
217+
/// <summary>
218+
/// Converts a source value to the target type.
219+
/// </summary>
220+
/// <param name="value"></param>
221+
/// <param name="parameter"></param>
222+
/// <param name="language"></param>
223+
/// <returns></returns>
224+
protected override Visibility Convert(object? value, object? parameter, string? language)
225+
{
226+
return value is null ? Visibility.Collapsed : Visibility.Visible;
227+
}
228+
229+
/// <summary>
230+
/// Converts a target value back to the source type.
231+
/// </summary>
232+
/// <param name="value"></param>
233+
/// <param name="parameter"></param>
234+
/// <param name="language"></param>
235+
/// <returns></returns>
236+
protected override object? ConvertBack(Visibility value, object? parameter, string? language)
237+
{
238+
return new NotSupportedException();
239+
}
240+
}
214241
}

src/Files.App/UserControls/StatusBarControl.xaml

Lines changed: 76 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<UserControl.Resources>
1616
<converters:NullToTrueConverter x:Key="NullToFalseConverter" Inverse="True" />
17+
<converters:NullToVisibilityCollapsedConverter x:Key="NullToVisibilityCollapsedConverter" />
1718

1819
<Style x:Key="Local.RadioButtonStyle" TargetType="RadioButton">
1920
<Setter Property="Foreground" Value="{ThemeResource TextFillColorSecondaryBrush}" />
@@ -100,10 +101,11 @@
100101
</Style>
101102
</UserControl.Resources>
102103

103-
<Grid Padding="8,0" ColumnSpacing="8">
104+
<Grid Padding="8,0" ColumnSpacing="4">
104105
<Grid.ColumnDefinitions>
105106
<ColumnDefinition />
106107
<ColumnDefinition Width="Auto" />
108+
<ColumnDefinition Width="Auto" />
107109
</Grid.ColumnDefinitions>
108110
<StackPanel
109111
Grid.Column="0"
@@ -201,83 +203,86 @@
201203
<TextBlock Text="{x:Bind DirectoryPropertiesViewModel.PullInfo, Mode=OneWay}" />
202204
</StackPanel>
203205
</Button>
206+
</StackPanel>
204207

205-
<Button
206-
x:Name="GitBranch"
207-
Height="24"
208-
Padding="8,0,8,0"
209-
Background="Transparent"
210-
BorderBrush="Transparent"
211-
ToolTipService.ToolTip="{helpers:ResourceString Name=ManageBranches}">
212-
213-
<Button.Content>
214-
<StackPanel Orientation="Horizontal" Spacing="8">
215-
<usercontrols:OpacityIcon Style="{StaticResource ColorIconGitBranches}" />
216-
217-
<!-- Branch Name -->
218-
<TextBlock Text="{x:Bind DirectoryPropertiesViewModel.GitBranchDisplayName, Mode=OneWay}" />
219-
</StackPanel>
220-
</Button.Content>
208+
<!-- Use visibility because it causes a crash to use a TwoWay x:Bind on an element that is inside an element with x:Load (#12589, #12599) -->
209+
<Button
210+
x:Name="GitBranch"
211+
Grid.Column="2"
212+
Height="24"
213+
Padding="8,0,8,0"
214+
Background="Transparent"
215+
BorderBrush="Transparent"
216+
ToolTipService.ToolTip="{helpers:ResourceString Name=ManageBranches}"
217+
Visibility="{x:Bind DirectoryPropertiesViewModel.GitBranchDisplayName, Mode=OneWay, Converter={StaticResource NullToVisibilityCollapsedConverter}}">
221218

222-
<Button.Flyout>
223-
<Flyout x:Name="BranchesFlyout" Opening="BranchesFlyout_Opening">
224-
<Grid
225-
Width="300"
226-
Height="340"
227-
Margin="-16">
228-
<Grid.RowDefinitions>
229-
<RowDefinition Height="Auto" />
230-
<RowDefinition Height="*" />
231-
</Grid.RowDefinitions>
219+
<Button.Content>
220+
<StackPanel Orientation="Horizontal" Spacing="8">
221+
<usercontrols:OpacityIcon Style="{StaticResource ColorIconGitBranches}" />
232222

233-
<!-- Header -->
234-
<Grid
235-
Grid.Row="0"
236-
Padding="4,8,8,8"
237-
Background="{ThemeResource AcrylicBackgroundFillColorDefaultBrush}"
238-
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
239-
BorderThickness="0,0,0,1">
223+
<!-- Branch Name -->
224+
<TextBlock Text="{x:Bind DirectoryPropertiesViewModel.GitBranchDisplayName, Mode=OneWay}" />
225+
</StackPanel>
226+
</Button.Content>
240227

241-
<!-- Locals and Remotes -->
242-
<StackPanel
243-
Grid.Row="1"
244-
HorizontalAlignment="Left"
245-
VerticalAlignment="Center"
246-
Orientation="Horizontal">
247-
<RadioButton
248-
Content="{helpers:ResourceString Name=Locals}"
249-
IsChecked="{x:Bind DirectoryPropertiesViewModel.ShowLocals, Mode=TwoWay}"
250-
Style="{StaticResource Local.RadioButtonStyle}" />
251-
<RadioButton Content="{helpers:ResourceString Name=Remotes}" Style="{StaticResource Local.RadioButtonStyle}" />
252-
</StackPanel>
228+
<Button.Flyout>
229+
<Flyout x:Name="BranchesFlyout" Opening="BranchesFlyout_Opening">
230+
<Grid
231+
Width="300"
232+
Height="340"
233+
Margin="-16">
234+
<Grid.RowDefinitions>
235+
<RowDefinition Height="Auto" />
236+
<RowDefinition Height="*" />
237+
</Grid.RowDefinitions>
253238

254-
<!-- New Branch Button -->
255-
<Button
256-
x:Name="NewBranchButton"
257-
Height="24"
258-
Padding="8,0"
259-
HorizontalAlignment="Right"
260-
Command="{x:Bind DirectoryPropertiesViewModel.NewBranchCommand, Mode=OneWay}"
261-
Content="{helpers:ResourceString Name=CreateBranch}"
262-
FontSize="12"
263-
ToolTipService.ToolTip="{helpers:ResourceString Name=CreateBranch}" />
264-
</Grid>
239+
<!-- Header -->
240+
<Grid
241+
Grid.Row="0"
242+
Padding="4,8,8,8"
243+
Background="{ThemeResource AcrylicBackgroundFillColorDefaultBrush}"
244+
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
245+
BorderThickness="0,0,0,1">
265246

266-
<!-- Branches List -->
267-
<ListView
268-
x:Name="BranchesList"
247+
<!-- Locals and Remotes -->
248+
<StackPanel
269249
Grid.Row="1"
270-
Padding="4"
271-
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
272-
IsItemClickEnabled="True"
273-
ItemClick="BranchesList_ItemClick"
274-
ItemsSource="{x:Bind DirectoryPropertiesViewModel.BranchesNames, Mode=OneWay}"
275-
SelectedIndex="{x:Bind DirectoryPropertiesViewModel.SelectedBranchIndex, Mode=TwoWay}"
276-
SelectionMode="Single" />
250+
HorizontalAlignment="Left"
251+
VerticalAlignment="Center"
252+
Orientation="Horizontal">
253+
<RadioButton
254+
Content="{helpers:ResourceString Name=Locals}"
255+
IsChecked="{x:Bind DirectoryPropertiesViewModel.ShowLocals, Mode=TwoWay}"
256+
Style="{StaticResource Local.RadioButtonStyle}" />
257+
<RadioButton Content="{helpers:ResourceString Name=Remotes}" Style="{StaticResource Local.RadioButtonStyle}" />
258+
</StackPanel>
259+
260+
<!-- New Branch Button -->
261+
<Button
262+
x:Name="NewBranchButton"
263+
Height="24"
264+
Padding="8,0"
265+
HorizontalAlignment="Right"
266+
Command="{x:Bind DirectoryPropertiesViewModel.NewBranchCommand, Mode=OneWay}"
267+
Content="{helpers:ResourceString Name=CreateBranch}"
268+
FontSize="12"
269+
ToolTipService.ToolTip="{helpers:ResourceString Name=CreateBranch}" />
277270
</Grid>
278-
</Flyout>
279-
</Button.Flyout>
280-
</Button>
281-
</StackPanel>
271+
272+
<!-- Branches List -->
273+
<ListView
274+
x:Name="BranchesList"
275+
Grid.Row="1"
276+
Padding="4"
277+
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
278+
IsItemClickEnabled="True"
279+
ItemClick="BranchesList_ItemClick"
280+
ItemsSource="{x:Bind DirectoryPropertiesViewModel.BranchesNames, Mode=OneWay}"
281+
SelectedIndex="{x:Bind DirectoryPropertiesViewModel.SelectedBranchIndex, Mode=TwoWay}"
282+
SelectionMode="Single" />
283+
</Grid>
284+
</Flyout>
285+
</Button.Flyout>
286+
</Button>
282287
</Grid>
283288
</UserControl>

0 commit comments

Comments
 (0)