Skip to content

Commit 1e9476e

Browse files
authored
Fix: Fixed issue where resizing window would reload preview (#14227)
1 parent ddf3b2a commit 1e9476e

File tree

4 files changed

+39
-35
lines changed

4 files changed

+39
-35
lines changed

src/Files.App/ViewModels/MainPageViewModel.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ public TabBarItem? SelectedTabItem
3636
set => SetProperty(ref selectedTabItem, value);
3737
}
3838

39+
private bool shouldViewControlBeDisplayed;
40+
public bool ShouldViewControlBeDisplayed
41+
{
42+
get => shouldViewControlBeDisplayed;
43+
set => SetProperty(ref shouldViewControlBeDisplayed, value);
44+
}
45+
46+
private bool shouldPreviewPaneBeActive;
47+
public bool ShouldPreviewPaneBeActive
48+
{
49+
get => shouldPreviewPaneBeActive;
50+
set => SetProperty(ref shouldPreviewPaneBeActive, value);
51+
}
52+
53+
private bool shouldPreviewPaneBeDisplayed;
54+
public bool ShouldPreviewPaneBeDisplayed
55+
{
56+
get => shouldPreviewPaneBeDisplayed;
57+
set => SetProperty(ref shouldPreviewPaneBeDisplayed, value);
58+
}
59+
3960
// Commands
4061

4162
public ICommand NavigateToNumberedTabKeyboardAcceleratorCommand { get; }

src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private void ContentPageContext_PropertyChanged(object? sender, PropertyChangedE
129129
else
130130
SelectedItem = null;
131131

132-
var shouldUpdatePreview = ((MainWindow.Instance.Content as Frame)?.Content as MainPage)?.ShouldPreviewPaneBeActive;
132+
var shouldUpdatePreview = ((MainWindow.Instance.Content as Frame)?.Content as MainPage)?.ViewModel.ShouldPreviewPaneBeActive;
133133
if (shouldUpdatePreview == true)
134134
_ = UpdateSelectedItemPreviewAsync();
135135
break;

src/Files.App/Views/MainPage.xaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
xmlns:sidebar="using:Files.App.UserControls.Sidebar"
1212
xmlns:tabbar="using:Files.App.UserControls.TabBar"
1313
xmlns:toolkit="using:CommunityToolkit.WinUI.UI.Controls"
14-
xmlns:triggers="using:CommunityToolkit.WinUI.UI.Triggers"
1514
xmlns:uc="using:Files.App.UserControls"
1615
xmlns:viewmodels="using:Files.App.ViewModels"
1716
xmlns:wctconverters="using:CommunityToolkit.WinUI.UI.Converters"
@@ -238,8 +237,8 @@
238237
Grid.ColumnSpan="3"
239238
x:Load="False"
240239
Loaded="NavToolbar_Loaded"
241-
ShowPreviewPaneButton="{x:Bind ShouldPreviewPaneBeDisplayed, Mode=OneWay}"
242-
ShowViewControlButton="{x:Bind ShouldViewControlBeDisplayed, Mode=OneWay}"
240+
ShowPreviewPaneButton="{x:Bind ViewModel.ShouldPreviewPaneBeDisplayed, Mode=OneWay}"
241+
ShowViewControlButton="{x:Bind ViewModel.ShouldViewControlBeDisplayed, Mode=OneWay}"
243242
TabIndex="2" />
244243

245244
<!-- Page Content -->
@@ -255,7 +254,7 @@
255254
x:Name="PaneSplitter"
256255
Grid.Row="1"
257256
Grid.Column="1"
258-
x:Load="{x:Bind ShouldPreviewPaneBeActive, Mode=OneWay}"
257+
x:Load="{x:Bind ViewModel.ShouldPreviewPaneBeActive, Mode=OneWay}"
259258
ManipulationCompleted="PaneSplitter_ManipulationCompleted"
260259
ManipulationStarted="PaneSplitter_ManipulationStarted"
261260
ResizeBehavior="BasedOnAlignment"
@@ -267,7 +266,7 @@
267266
Grid.Row="1"
268267
Grid.Column="2"
269268
HorizontalContentAlignment="Stretch"
270-
x:Load="{x:Bind ShouldPreviewPaneBeActive, Mode=OneWay}"
269+
x:Load="{x:Bind ViewModel.ShouldPreviewPaneBeActive, Mode=OneWay}"
271270
Loaded="PreviewPane_Loaded"
272271
Unloaded="PreviewPane_Unloaded" />
273272

src/Files.App/Views/MainPage.xaml.cs

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Microsoft.UI.Xaml.Controls;
1313
using Microsoft.UI.Xaml.Input;
1414
using Microsoft.UI.Xaml.Navigation;
15-
using System.Runtime.CompilerServices;
1615
using Windows.ApplicationModel;
1716
using Windows.Foundation.Metadata;
1817
using Windows.Services.Store;
@@ -21,7 +20,7 @@
2120

2221
namespace Files.App.Views
2322
{
24-
public sealed partial class MainPage : Page, INotifyPropertyChanged
23+
public sealed partial class MainPage : Page
2524
{
2625
public IUserSettingsService UserSettingsService { get; }
2726
public IApplicationService ApplicationService { get; }
@@ -62,6 +61,7 @@ public MainPage()
6261
if (FilePropertiesHelpers.FlowDirectionSettingIsRightToLeft)
6362
FlowDirection = FlowDirection.RightToLeft;
6463

64+
ViewModel.PropertyChanged += ViewModel_PropertyChanged;
6565
UserSettingsService.OnSettingChangedEvent += UserSettingsService_OnSettingChangedEvent;
6666

6767
_updateDateDisplayTimer = DispatcherQueue.CreateTimer();
@@ -363,7 +363,7 @@ private void SidebarControl_Loaded(object sender, RoutedEventArgs e)
363363
/// </summary>
364364
private void UpdatePositioning()
365365
{
366-
if (PreviewPane is null || !ShouldPreviewPaneBeActive)
366+
if (PreviewPane is null || !ViewModel.ShouldPreviewPaneBeActive)
367367
{
368368
PaneRow.MinHeight = 0;
369369
PaneRow.MaxHeight = double.MaxValue;
@@ -434,39 +434,23 @@ private void PaneSplitter_ManipulationCompleted(object sender, ManipulationCompl
434434
this.ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.Arrow));
435435
}
436436

437-
public bool ShouldViewControlBeDisplayed => SidebarAdaptiveViewModel.PaneHolder?.ActivePane?.InstanceViewModel?.IsPageTypeNotHome ?? false;
438-
439-
public bool ShouldPreviewPaneBeActive => UserSettingsService.InfoPaneSettingsService.IsEnabled && ShouldPreviewPaneBeDisplayed;
440-
441-
public bool ShouldPreviewPaneBeDisplayed
437+
private void LoadPaneChanged()
442438
{
443-
get
444-
{
445-
var isHomePage = !(SidebarAdaptiveViewModel.PaneHolder?.ActivePane?.InstanceViewModel?.IsPageTypeNotHome ?? false);
446-
var isMultiPane = SidebarAdaptiveViewModel.PaneHolder?.IsMultiPaneActive ?? false;
447-
var isBigEnough = MainWindow.Instance.Bounds.Width > 450 && MainWindow.Instance.Bounds.Height > 450 || RootGrid.ActualWidth > 700 && MainWindow.Instance.Bounds.Height > 360;
448-
var isEnabled = (!isHomePage || isMultiPane) && isBigEnough;
439+
var isHomePage = !(SidebarAdaptiveViewModel.PaneHolder?.ActivePane?.InstanceViewModel?.IsPageTypeNotHome ?? false);
440+
var isMultiPane = SidebarAdaptiveViewModel.PaneHolder?.IsMultiPaneActive ?? false;
441+
var isBigEnough = MainWindow.Instance.Bounds.Width > 450 && MainWindow.Instance.Bounds.Height > 450 || RootGrid.ActualWidth > 700 && MainWindow.Instance.Bounds.Height > 360;
449442

450-
return isEnabled;
451-
}
452-
}
443+
ViewModel.ShouldPreviewPaneBeDisplayed = (!isHomePage || isMultiPane) && isBigEnough;
444+
ViewModel.ShouldPreviewPaneBeActive = UserSettingsService.InfoPaneSettingsService.IsEnabled && ViewModel.ShouldPreviewPaneBeDisplayed;
445+
ViewModel.ShouldViewControlBeDisplayed = SidebarAdaptiveViewModel.PaneHolder?.ActivePane?.InstanceViewModel?.IsPageTypeNotHome ?? false;
453446

454-
private void LoadPaneChanged()
455-
{
456-
OnPropertyChanged(nameof(ShouldViewControlBeDisplayed));
457-
OnPropertyChanged(nameof(ShouldPreviewPaneBeActive));
458-
OnPropertyChanged(nameof(ShouldPreviewPaneBeDisplayed));
459447
UpdatePositioning();
460448
}
461449

462-
public event PropertyChangedEventHandler? PropertyChanged;
463-
464-
private void OnPropertyChanged([CallerMemberName] string propertyName = "")
450+
private async void ViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs e)
465451
{
466-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
467-
468-
if (propertyName == nameof(ShouldPreviewPaneBeActive) && ShouldPreviewPaneBeActive)
469-
_ = Ioc.Default.GetRequiredService<InfoPaneViewModel>().UpdateSelectedItemPreviewAsync();
452+
if (e.PropertyName == nameof(ViewModel.ShouldPreviewPaneBeActive) && ViewModel.ShouldPreviewPaneBeActive)
453+
await Ioc.Default.GetRequiredService<InfoPaneViewModel>().UpdateSelectedItemPreviewAsync();
470454
}
471455

472456
private void RootGrid_PreviewKeyDown(object sender, KeyRoutedEventArgs e)

0 commit comments

Comments
 (0)