-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Controls Search Bar #661
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,39 @@ public partial class MainWindowViewModel : ObservableObject | |
[ObservableProperty] | ||
private string _applicationTitle = "WPF Gallery Preview"; | ||
|
||
private ObservableCollection<string> SearchItems { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the need for search items ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It contains the list of all pages in string format. This is then used to filter out from this whole set without changing the original FilteredSearchItems. |
||
|
||
public ObservableCollection<string> FilteredSearchItems { get; set; } | ||
|
||
private string _searchBoxText; | ||
|
||
public string SearchBoxText | ||
{ | ||
get => _searchBoxText; | ||
set | ||
{ | ||
_searchBoxText = value; | ||
OnPropertyChanged(nameof(SearchBoxText)); | ||
FilterItems(); | ||
} | ||
} | ||
|
||
private void FilterItems() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should go in ControlsInfoDataSource.cs . |
||
{ | ||
if (string.IsNullOrEmpty(SearchBoxText)) | ||
{ | ||
FilteredSearchItems = new ObservableCollection<string>(SearchItems); | ||
} | ||
else | ||
{ | ||
FilteredSearchItems = new ObservableCollection<string>( | ||
SearchItems.Where(item => item.ToLower().Contains(SearchBoxText.ToLower())) | ||
); | ||
} | ||
|
||
OnPropertyChanged(nameof(FilteredSearchItems)); | ||
} | ||
|
||
private readonly DispatcherTimer _timer; | ||
|
||
private string _searchText = string.Empty; | ||
|
@@ -56,6 +89,20 @@ public MainWindowViewModel(INavigationService navigationService) | |
_timer = new DispatcherTimer(); | ||
_timer.Interval = TimeSpan.FromMilliseconds(400); | ||
_timer.Tick += PerformSearchNavigation; | ||
|
||
SearchItems = new(); | ||
|
||
foreach (ControlInfoDataItem mainPage in Controls) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even this should go in ControlsInfoDataSource.cs |
||
{ | ||
SearchItems.Add(mainPage.ToString()); | ||
|
||
foreach (ControlInfoDataItem controlsPage in mainPage.Items) | ||
{ | ||
SearchItems.Add(controlsPage.ToString()); | ||
} | ||
} | ||
|
||
FilteredSearchItems = new ObservableCollection<string>(SearchItems); | ||
} | ||
|
||
public void UpdateSearchText(string searchText) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the behavior when we navigate on the drop down using arrow keys ? For A11y, we will have to avoid selection, but I am guessing that's working correctly. I will try to run the changes and check it out. Overall, good work.