Repository: microsoft/PowerToys
File: src/modules/peek/Peek.UI/MainWindow.xaml.cs (C#)

Code before:
        private const double WindowWidthContentPadding = 7;
        private const double WindowHeightContentPadding = 16;

        public MainWindow()
        {
            InitializeComponent();

            ViewModel = new MainWindowViewModel();

            NativeEventWaiter.WaitForEventLoop(Constants.ShowPeekEvent(), OnPeekHotkey);

            TitleBarControl.SetToWindow(this);

            AppWindow.Closing += AppWindow_Closing;
        }

        public MainWindowViewModel ViewModel { get; }

        /// <summary>
        /// Handle Peek hotkey, by toggling the window visibility and querying files when necessary.
        /// </summary>
        private void OnPeekHotkey()
        {
            if (AppWindow.IsVisible)
            {
                ExecuteHide();
            }
            else
            {
                // TODO: move into general ViewModel method when needed
                ViewModel.FileQuery.Initialize();
            }
        }

        private void LeftNavigationInvoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
        {
            ViewModel.AttemptLeftNavigation();
        }

        private void RightNavigationInvoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
        {
            ViewModel.AttemptRightNavigation();
        }

        private void ExecuteHide()
        {
            this.Hide();

            // TODO: move into general ViewModel method when needed
            ViewModel.FileQuery.Uninitialize();
        }

Review comment (suggestion):
nit: I am not convinced with this naming. Maybe Init/Unit naming should be in here since this is the start of the app and init means starting the query and uninit means hiding+canceling+clearing.

Code after:
        private const double WindowWidthContentPadding = 7;
        private const double WindowHeightContentPadding = 16;

        public MainWindow()
        {
            InitializeComponent();

            ViewModel = new MainWindowViewModel();

            NativeEventWaiter.WaitForEventLoop(Constants.ShowPeekEvent(), OnPeekHotkey);

            TitleBarControl.SetToWindow(this);

            AppWindow.Closing += AppWindow_Closing;
        }

        public MainWindowViewModel ViewModel { get; }

        /// <summary>
        /// Handle Peek hotkey, by toggling the window visibility and querying files when necessary.
        /// </summary>
        private void OnPeekHotkey()
        {
            if (AppWindow.IsVisible)
            {
                Uninitialize();
            }
            else
            {
                Initialize();
            }
        }

        private void LeftNavigationInvoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
        {
            ViewModel.AttemptLeftNavigation();
        }

        private void RightNavigationInvoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
        {
            ViewModel.AttemptRightNavigation();
        }

        private void Initialize()
        {
            ViewModel.FolderItemsQuery.Start();
        }

        private void Uninitialize()
        {
            this.Hide();