Consider the following situation:
- MVVM Pattern
- AutosuggestBox in the title bar
- Doing something like searching through a box in all views
implement ITitleBarAutoSuggestBoxAware
in your viewmodels:
1 2 3 4 5 6 7 8 9 10 11 12
| public partial class GalleryViewModel : ITitleBarAutoSuggestBoxAware { public void OnAutoSuggestBoxTextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args) { Search(sender.Text); }
public void OnAutoSuggestBoxQuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) { Search(sender.Text); } }
|
and in your MainPage or wherever your box is located:
1 2 3 4 5 6 7 8 9
| private void OnTextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args) { AutoSuggestBoxHelper.OnITitleBarAutoSuggestBoxTextChangedEvent(sender, args, NavFrame); }
private void OnQuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) { AutoSuggestBoxHelper.OnITitleBarAutoSuggestBoxQuerySubmittedEvent(sender, args, NavFrame); }
|
then you should set DataContext to your ViewModel:
1 2 3 4 5 6
| public GalleryPage() { ViewModel = App.GetService<GalleryViewModel>(); this.InitializeComponent(); DataContext = ViewModel; }
|
1 2 3 4 5 6
| public ArchivePage() { ViewModel = App.GetService<ArchiveViewModel>(); this.InitializeComponent(); DataContext = ViewModel; }
|