89 lines
2.5 KiB
C#
89 lines
2.5 KiB
C#
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
|
|
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
|
|
// All Rights Reserved.
|
|
|
|
using WPFluent.Controls;
|
|
using WPFluent.Gallery.Services.Contracts;
|
|
using WPFluent.Gallery.ViewModels.Windows;
|
|
using WPFluent.Gallery.Views.Pages;
|
|
|
|
namespace WPFluent.Gallery.Views.Windows;
|
|
|
|
public partial class MainWindow : IWindow
|
|
{
|
|
public MainWindow(
|
|
MainWindowViewModel viewModel,
|
|
INavigationService navigationService,
|
|
IServiceProvider serviceProvider,
|
|
ISnackbarService snackbarService,
|
|
IContentDialogService contentDialogService
|
|
)
|
|
{
|
|
//适应当前系统的主题
|
|
//Appearance.SystemThemeWatcher.Watch(this);
|
|
|
|
ViewModel = viewModel;
|
|
DataContext = this;
|
|
|
|
InitializeComponent();
|
|
|
|
snackbarService.SetSnackbarPresenter(SnackbarPresenter);
|
|
navigationService.SetNavigationControl(NavigationView);
|
|
contentDialogService.SetDialogHost(RootContentDialog);
|
|
}
|
|
|
|
public MainWindowViewModel ViewModel { get; }
|
|
|
|
private bool _isUserClosedPane;
|
|
|
|
private bool _isPaneOpenedOrClosedFromCode;
|
|
|
|
private void OnNavigationSelectionChanged(object sender, RoutedEventArgs e)
|
|
{
|
|
if (sender is not WPFluent.Controls.NavigationView navigationView)
|
|
{
|
|
return;
|
|
}
|
|
|
|
NavigationView.SetCurrentValue(
|
|
NavigationView.HeaderVisibilityProperty,
|
|
navigationView.SelectedItem?.TargetPageType != typeof(DashboardPage)
|
|
? Visibility.Visible
|
|
: Visibility.Collapsed
|
|
);
|
|
}
|
|
|
|
private void MainWindow_OnSizeChanged(object sender, SizeChangedEventArgs e)
|
|
{
|
|
if (_isUserClosedPane)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_isPaneOpenedOrClosedFromCode = true;
|
|
NavigationView.SetCurrentValue(NavigationView.IsPaneOpenProperty, e.NewSize.Width > 1200);
|
|
_isPaneOpenedOrClosedFromCode = false;
|
|
}
|
|
|
|
private void NavigationView_OnPaneOpened(NavigationView sender, RoutedEventArgs args)
|
|
{
|
|
if (_isPaneOpenedOrClosedFromCode)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_isUserClosedPane = false;
|
|
}
|
|
|
|
private void NavigationView_OnPaneClosed(NavigationView sender, RoutedEventArgs args)
|
|
{
|
|
if (_isPaneOpenedOrClosedFromCode)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_isUserClosedPane = true;
|
|
}
|
|
}
|