From 6810d2cd8abdd53c31f377fbbcf09ea6d564314e Mon Sep 17 00:00:00 2001 From: Michael Hawker <24302614+michael-hawker@users.noreply.github.com> Date: Mon, 9 Dec 2024 23:55:01 -0800 Subject: [PATCH] Add some memory to the SearchBox based on the last Filter of the VM --- .../Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs index 58792261d1..5a338f6614 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs @@ -35,7 +35,19 @@ public sealed partial class SearchBar : UserControl, ICurrentPageAware // Using a DependencyProperty as the backing store for CurrentPageViewModel. This enables animation, styling, binding, etc... public static readonly DependencyProperty CurrentPageViewModelProperty = - DependencyProperty.Register(nameof(CurrentPageViewModel), typeof(PageViewModel), typeof(SearchBar), new PropertyMetadata(null)); + DependencyProperty.Register(nameof(CurrentPageViewModel), typeof(PageViewModel), typeof(SearchBar), new PropertyMetadata(null, OnCurrentPageViewModelChanged)); + + private static void OnCurrentPageViewModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + //// TODO: If the Debounce timer hasn't fired, we may want to store the current Filter in the OldValue/prior VM, but we don't want that to go actually do work... + + if (d is SearchBar @this + && e.NewValue is PageViewModel page) + { + // TODO: In some cases we probably want commands to clear a filter somewhere in the process, so we need to figure out when that is. + @this.FilterBox.Text = page.Filter; + } + } public SearchBar() {