Ghost1372

everything can be handy

ITitleBarAutoSuggestBoxAware

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 ServerViewModel : 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
10
11
12
13
14
15
16
17
private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
var viewModel = NavFrame.GetPageViewModel();
if (viewModel != null && viewModel is ITitleBarAutoSuggestBoxAware titleBarAutoSuggestBoxAware)
{
titleBarAutoSuggestBoxAware.OnAutoSuggestBoxTextChanged(sender, args);
}
}

private void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
var viewModel = NavFrame.GetPageViewModel();
if (viewModel != null && viewModel is ITitleBarAutoSuggestBoxAware titleBarAutoSuggestBoxAware)
{
titleBarAutoSuggestBoxAware.OnAutoSuggestBoxQuerySubmitted(sender, args);
}
}
0%