Skip to content

Commit 176c9c3

Browse files
authored
Fix: Fixed column tracing in Columns View (#18650)
1 parent e124bb5 commit 176c9c3

2 files changed

Lines changed: 20 additions & 31 deletions

File tree

src/Files.App/Views/Layouts/ColumnLayoutPage.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@
148148
<Setter Property="Padding" Value="4,0" />
149149
</Style>
150150

151+
<Style x:Key="PathTracedRowStyle" TargetType="Grid">
152+
<Setter Property="Background" Value="{ThemeResource ListViewItemBackgroundSelected}" />
153+
</Style>
154+
151155
</local:BaseGroupableLayoutPage.Resources>
152156

153157
<Grid x:Name="RootGrid" ContextFlyout="{x:Bind BaseContextMenuFlyout}">

src/Files.App/Views/Layouts/ColumnLayoutPage.xaml.cs

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Microsoft.UI.Xaml;
99
using Microsoft.UI.Xaml.Controls;
1010
using Microsoft.UI.Xaml.Input;
11-
using Microsoft.UI.Xaml.Media;
1211
using Microsoft.UI.Xaml.Navigation;
1312
using System.IO;
1413
using Windows.Storage;
@@ -88,6 +87,19 @@ public ColumnLayoutPage() : base()
8887
doubleClickTimer = DispatcherQueue.CreateTimer();
8988
}
9089

90+
private void SetOpenedFolder(ListViewItem? lvi)
91+
{
92+
SetRowStyle(openedFolderPresenter, null);
93+
openedFolderPresenter = lvi;
94+
SetRowStyle(openedFolderPresenter, this.Resources["PathTracedRowStyle"] as Style);
95+
}
96+
97+
private static void SetRowStyle(ListViewItem? lvi, Style? style)
98+
{
99+
if (lvi?.FindDescendant<Grid>() is Grid row)
100+
row.Style = style;
101+
}
102+
91103
// Methods
92104

93105
private void OnItemLoadStatusChanged(object sender, ItemLoadStatusChangedEventArgs args)
@@ -117,19 +129,10 @@ private void ColumnViewBase_GotFocus(object sender, RoutedEventArgs e)
117129

118130
private void ColumnViewBase_ItemInvoked(object? sender, EventArgs e)
119131
{
120-
ClearOpenedFolderSelectionIndicator();
121-
openedFolderPresenter = FileList.ContainerFromItem(FileList.SelectedItem) as ListViewItem;
132+
SetOpenedFolder(FileList.ContainerFromItem(FileList.SelectedItem) as ListViewItem);
122133
}
123134

124-
internal void ClearOpenedFolderSelectionIndicator()
125-
{
126-
if (openedFolderPresenter is null)
127-
return;
128-
129-
openedFolderPresenter.Background = new SolidColorBrush(Microsoft.UI.Colors.Transparent);
130-
SetFolderBackground(openedFolderPresenter, new SolidColorBrush(Microsoft.UI.Colors.Transparent));
131-
openedFolderPresenter = null;
132-
}
135+
internal void ClearOpenedFolderSelectionIndicator() => SetOpenedFolder(null);
133136

134137
protected override void ItemManipulationModel_ScrollIntoViewInvoked(object? sender, ListedItem e)
135138
{
@@ -196,9 +199,7 @@ private void HighlightPathDirectory(ListViewBase sender, ContainerContentChangin
196199
if (args.Item is ListedItem item && columnsOwner?.OwnerPath is string ownerPath
197200
&& (ownerPath == item.ItemPath || (ownerPath.Length > item.ItemPath.Length && ownerPath.StartsWith(item.ItemPath) && ownerPath[item.ItemPath.Length] is '/' or '\\')))
198201
{
199-
SetFolderBackground(args.ItemContainer as ListViewItem, this.Resources["ListViewItemBackgroundSelected"] as SolidColorBrush);
200-
201-
openedFolderPresenter = FileList.ContainerFromItem(item) as ListViewItem;
202+
SetOpenedFolder(FileList.ContainerFromItem(item) as ListViewItem);
202203
FileList.ContainerContentChanging -= HighlightPathDirectory;
203204
}
204205
}
@@ -338,11 +339,6 @@ protected override void OnSelectionChanged(SelectionChangedEventArgs e)
338339
if (e.AddedItems.Count > 0)
339340
columnsOwner?.HandleSelectionChange(this);
340341

341-
if (e.RemovedItems.Count > 0 && openedFolderPresenter != null)
342-
{
343-
SetFolderBackground(openedFolderPresenter, this.Resources["ListViewItemBackgroundSelected"] as SolidColorBrush);
344-
}
345-
346342
if (SelectedItems?.Count == 1 && SelectedItem?.PrimaryItemAttribute is StorageItemTypes.Folder)
347343
{
348344
TryOpenSelectedFolder();
@@ -692,16 +688,5 @@ internal void ClearSelectionIndicator()
692688
FileList.SelectedItem = null;
693689
LockPreviewPaneContent = false;
694690
}
695-
696-
private static void SetFolderBackground(ListViewItem? lvi, SolidColorBrush? backgroundColor)
697-
{
698-
if (lvi == null || backgroundColor == null) return;
699-
700-
701-
if (lvi.FindDescendant<Grid>() is Grid presenter)
702-
{
703-
presenter.Background = backgroundColor;
704-
}
705-
}
706691
}
707692
}

0 commit comments

Comments
 (0)