-
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 SearchBox to Gallery #662
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 | ||||
---|---|---|---|---|---|---|
|
@@ -53,6 +53,8 @@ public sealed class ControlsInfoDataSource | |||||
|
||||||
private static readonly ControlsInfoDataSource _instance; | ||||||
|
||||||
private ICollection<ControlInfoDataItem> _allPages; | ||||||
|
||||||
public static ControlsInfoDataSource Instance | ||||||
{ | ||||||
get | ||||||
|
@@ -70,6 +72,8 @@ private ControlsInfoDataSource() | |||||
{ | ||||||
var jsonText = ReadControlsData(); | ||||||
ControlsInfo = JsonSerializer.Deserialize<List<ControlInfoDataItem>>(jsonText); | ||||||
|
||||||
GetAllPages(); | ||||||
} | ||||||
|
||||||
#endregion | ||||||
|
@@ -111,6 +115,39 @@ public ICollection<ControlInfoDataItem> GetAllControlsInfo() | |||||
return allControls; | ||||||
} | ||||||
|
||||||
private void GetAllPages() | ||||||
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.
Suggested change
|
||||||
{ | ||||||
_allPages = new ObservableCollection<ControlInfoDataItem>(); | ||||||
|
||||||
foreach (ControlInfoDataItem groupPage in ControlsInfo) | ||||||
{ | ||||||
_allPages.Add(groupPage); | ||||||
|
||||||
foreach (ControlInfoDataItem controlPage in groupPage.Items) | ||||||
{ | ||||||
_allPages.Add(controlPage); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
public ObservableCollection<ControlInfoDataItem> FilterItems(string filterText) | ||||||
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. Why not return |
||||||
{ | ||||||
ObservableCollection<ControlInfoDataItem> filteredItems = new(); | ||||||
|
||||||
if (string.IsNullOrEmpty(filterText)) | ||||||
{ | ||||||
filteredItems = new ObservableCollection<ControlInfoDataItem>(_allPages); | ||||||
} | ||||||
else | ||||||
{ | ||||||
filteredItems = new ObservableCollection<ControlInfoDataItem>( | ||||||
_allPages.Where(item => item.Title.ToLower().Contains(filterText.ToLower())) | ||||||
); | ||||||
} | ||||||
|
||||||
return filteredItems; | ||||||
} | ||||||
|
||||||
public ICollection<ControlInfoDataItem> GetGroupedControlsInfo() | ||||||
{ | ||||||
return ControlsInfo.Where(x => x.IsGroup == true && x.UniqueId != "Design Guidance" && x.UniqueId != "Samples").ToList(); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,26 @@ public partial class MainWindowViewModel : ObservableObject | |
|
||
[ObservableProperty] | ||
private ICollection<ControlInfoDataItem> _controls; | ||
|
||
[ObservableProperty] | ||
private ICollection<ControlInfoDataItem> _allPages; | ||
|
||
public ObservableCollection<ControlInfoDataItem> FilteredSearchItems { get; set; } | ||
|
||
private string _searchBoxText; | ||
|
||
public string SearchBoxText | ||
{ | ||
get => _searchBoxText; | ||
set | ||
{ | ||
_searchBoxText = value; | ||
OnPropertyChanged(nameof(SearchBoxText)); | ||
|
||
FilterItems(); | ||
} | ||
} | ||
|
||
[ObservableProperty] | ||
private ControlInfoDataItem? _selectedControl; | ||
private readonly INavigationService _navigationService; | ||
|
@@ -51,6 +71,20 @@ public void Forward() | |
public MainWindowViewModel(INavigationService navigationService) | ||
{ | ||
_controls = ControlsInfoDataSource.Instance.ControlsInfo; | ||
|
||
_allPages = new ObservableCollection<ControlInfoDataItem>(); | ||
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. You can just access the GetAllPages() function from ControlsInfoDataSource for this. |
||
foreach (ControlInfoDataItem groupControl in _controls) | ||
{ | ||
_allPages.Add(groupControl); | ||
|
||
foreach(ControlInfoDataItem control in groupControl.Items) | ||
{ | ||
_allPages.Add(control); | ||
} | ||
} | ||
|
||
FilteredSearchItems = new ObservableCollection<ControlInfoDataItem>(AllPages); | ||
|
||
_navigationService = navigationService; | ||
|
||
_timer = new DispatcherTimer(); | ||
|
@@ -65,6 +99,13 @@ public void UpdateSearchText(string searchText) | |
_timer.Start(); | ||
} | ||
|
||
private void FilterItems() | ||
{ | ||
FilteredSearchItems = ControlsInfoDataSource.Instance.FilterItems(SearchBoxText); | ||
|
||
OnPropertyChanged(nameof(FilteredSearchItems)); | ||
} | ||
|
||
private void PerformSearchNavigation(object? sender, EventArgs e) | ||
{ | ||
_timer.Stop(); | ||
|
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.