Best WinAppDriver code snippet using AppUIBasics.Common.NavigationHelper.NavigationHelper
ItemPage.xaml.cs
Source:ItemPage.xaml.cs
...23 /// A page that displays details for a single item within a group.24 /// </summary>25 public partial class ItemPage : Page26 {27 private NavigationHelper navigationHelper;28 private ControlInfoDataItem item;29 /// <summary>30 /// NavigationHelper is used on each page to aid in navigation and 31 /// process lifetime management32 /// </summary>33 public NavigationHelper NavigationHelper34 {35 get { return this.navigationHelper; }36 }37 public ControlInfoDataItem Item38 {39 get { return item; }40 set { item = value; }41 }42 public CommandBar BottomCommandBar43 {44 get { return bottomCommandBar; }45 }46 public ItemPage()47 {48 this.InitializeComponent();49 this.navigationHelper = new NavigationHelper(this);50 this.navigationHelper.LoadState += navigationHelper_LoadState;51 }52 /// <summary>53 /// Populates the page with content passed during navigation. Any saved state is also54 /// provided when recreating a page from a prior session.55 /// </summary>56 /// <param name="sender">57 /// The source of the event; typically <see cref="NavigationHelper"/>58 /// </param>59 /// <param name="e">Event data that provides both the navigation parameter passed to60 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and61 /// a dictionary of state preserved by this page during an earlier62 /// session. The state will be null the first time a page is visited.</param>63 private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)64 {65 var item = await ControlInfoDataSource.GetItemAsync((String)e.NavigationParameter);66 if (item != null)67 {68 Item = item;69 // Load control page into frame.70 var loader = new Windows.ApplicationModel.Resources.ResourceLoader();71 string pageRoot = loader.GetString("PageStringRoot");72 string pageString = pageRoot + item.UniqueId + "Page";73 Type pageType = Type.GetType(pageString);74 if (pageType != null)75 {76 this.contentFrame.Navigate(pageType);77 }78 if(item.Title == "AppBar")79 {80 //Child pages don't follow the visible bounds, so we need to add margin to account for this81 header.Margin = new Thickness(0, 24, 0, 0);82 }83 }84 }85 private void ThemeToggleButton_Checked(object sender, RoutedEventArgs e)86 {87 this.RequestedTheme = ElementTheme.Light;88 }89 private void ThemeToggleButton_Unchecked(object sender, RoutedEventArgs e)90 {91 this.RequestedTheme = ElementTheme.Dark;92 }93 protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)94 {95 base.OnNavigatingFrom(e);96 this.RequestedTheme = ElementTheme.Dark;97 }98 private void SearchButton_Click(object sender, RoutedEventArgs e)99 {100 this.Frame.Navigate(typeof(SearchResultsPage));101 }102 private void HelpButton_Click(object sender, RoutedEventArgs e)103 {104 ShowHelp();105 this.BottomAppBar.IsOpen = false;106 }107 protected void RelatedControl_Click(object sender, RoutedEventArgs e)108 {109 ButtonBase b = (ButtonBase)sender;110 NavigationRootPage.RootFrame.Navigate(typeof(ItemPage), b.Content.ToString());111 }112 private void ShowHelp()113 {114 var loader = new Windows.ApplicationModel.Resources.ResourceLoader();115 string HTMLOpenTags = loader.GetString("HTMLOpenTags");116 string HTMLCloseTags = loader.GetString("HTMLCloseTags");117 118 contentWebView.NavigateToString(HTMLOpenTags + Item.Content + HTMLCloseTags);119 if (!helpPopup.IsOpen)120 {121 rootPopupBorder.Width = 346;122 rootPopupBorder.Height = this.ActualHeight;123 helpPopup.HorizontalOffset = Window.Current.Bounds.Width - 346;124 helpPopup.IsOpen = true;125 }126 }127 private void SearchBox_QuerySubmitted(SearchBox sender, SearchBoxQuerySubmittedEventArgs args)128 {129 this.Frame.Navigate(typeof(SearchResultsPage), args.QueryText);130 }131 #region NavigationHelper registration132 /// The methods provided in this section are simply used to allow133 /// NavigationHelper to respond to the page's navigation methods.134 /// 135 /// Page specific logic should be placed in event handlers for the 136 /// <see cref="GridCS.Common.NavigationHelper.LoadState"/>137 /// and <see cref="GridCS.Common.NavigationHelper.SaveState"/>.138 /// The navigation parameter is available in the LoadState method 139 /// in addition to page state preserved during an earlier session.140 protected override void OnNavigatedTo(NavigationEventArgs e)141 {142 navigationHelper.OnNavigatedTo(e);143 }144 protected override void OnNavigatedFrom(NavigationEventArgs e)145 {146 navigationHelper.OnNavigatedFrom(e);147 }148 #endregion149 }150}...
SectionPage.xaml.cs
Source:SectionPage.xaml.cs
...33 /// within the group.34 /// </summary>35 public sealed partial class SectionPage : Page36 {37 private NavigationHelper navigationHelper;38 private ObservableDictionary defaultViewModel = new ObservableDictionary();39 ControlInfoDataGroup group;40 /// <summary>41 /// NavigationHelper is used on each page to aid in navigation and 42 /// process lifetime management43 /// </summary>44 public NavigationHelper NavigationHelper45 {46 get { return this.navigationHelper; }47 }48 /// <summary>49 /// This can be changed to a strongly typed view model.50 /// </summary>51 public ObservableDictionary DefaultViewModel52 {53 get { return this.defaultViewModel; }54 }55 public ControlInfoDataGroup Group56 {57 get { return group; }58 set { group = value; }59 }60 public SectionPage()61 {62 this.InitializeComponent();63 this.navigationHelper = new NavigationHelper(this);64 this.navigationHelper.LoadState += navigationHelper_LoadState;65 //controlsSearchBox.SuggestionsRequested += SearchResultsPage.SearchBox_SuggestionsRequested;66 }67 //private async void controlsSearchBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)68 //{69 // var groups = await AppUIBasics.Data.ControlInfoDataSource.GetGroupsAsync();70 // var suggestions = new List<ControlInfoDataItem>();71 // foreach (var group in groups)72 // {73 // var matchingItems = group.Items.Where(74 // item => item.Title.Contains(sender.Text));75 // foreach (var item in matchingItems)76 // {77 // suggestions.Add(item);78 // }79 // }80 // controlsSearchBox.ItemsSource = suggestions;81 //}82 //private void controlsSearchBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)83 //{84 // var itemId = (args.SelectedItem as ControlInfoDataItem).UniqueId;85 // this.Frame.Navigate(typeof(ItemPage), itemId);86 //}87 /// <summary>88 /// Populates the page with content passed during navigation. Any saved state is also89 /// provided when recreating a page from a prior session.90 /// </summary>91 /// <param name="sender">92 /// The source of the event; typically <see cref="NavigationHelper"/>93 /// </param>94 /// <param name="e">Event data that provides both the navigation parameter passed to95 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and96 /// a dictionary of state preserved by this page during an earlier97 /// session. The state will be null the first time a page is visited.</param>98 private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)99 {100 var group = await ControlInfoDataSource.GetGroupAsync((String)e.NavigationParameter);101 Group = group;102 }103 /// <summary>104 /// Invoked when an item is clicked.105 /// </summary>106 /// <param name="sender">The GridView displaying the item clicked.</param>107 /// <param name="e">Event data that describes the item clicked.</param>108 void ItemView_ItemClick(object sender, ItemClickEventArgs e)109 {110 // Navigate to the appropriate destination page, configuring the new page111 // by passing required information as a navigation parameter112 var itemId = ((ControlInfoDataItem)e.ClickedItem).UniqueId;113 this.Frame.Navigate(typeof(ItemPage), itemId);114 }115 private void SearchBox_QuerySubmitted(SearchBox sender, SearchBoxQuerySubmittedEventArgs args)116 {117 this.Frame.Navigate(typeof(SearchResultsPage), args.QueryText);118 }119 #region NavigationHelper registration120 /// The methods provided in this section are simply used to allow121 /// NavigationHelper to respond to the page's navigation methods.122 /// 123 /// Page specific logic should be placed in event handlers for the 124 /// <see cref="GridCS.Common.NavigationHelper.LoadState"/>125 /// and <see cref="GridCS.Common.NavigationHelper.SaveState"/>.126 /// The navigation parameter is available in the LoadState method 127 /// in addition to page state preserved during an earlier session.128 protected override void OnNavigatedTo(NavigationEventArgs e)129 {130 navigationHelper.OnNavigatedTo(e);131 }132 protected override void OnNavigatedFrom(NavigationEventArgs e)133 {134 navigationHelper.OnNavigatedFrom(e);135 }136 #endregion137 }138}...
NavigationHelper
Using AI Code Generation
1using AppUIBasics.Common;2using AppUIBasics.Data;3using AppUIBasics.ViewModels;4using AppUIBasics.Views;5using Windows.UI.Xaml.Controls;6{7 {8 private NavigationHelper navigationHelper;9 public NavigationViewPage()10 {11 InitializeComponent();12 navigationHelper = new NavigationHelper(this);13 navigationHelper.LoadState += NavigationHelper_LoadState;14 navigationHelper.SaveState += NavigationHelper_SaveState;15 }16 {17 get { return navigationHelper; }18 }19 private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)20 {21 if (e.PageState != null && e.PageState.ContainsKey("Selected"))22 {23 var selectedItem = e.PageState["Selected"] as Sample;24 navigationView.SelectedItem = navigationView.MenuItems.OfType<NavigationViewItem>().First(menuItem => (menuItem.Content as string) == selectedItem?.Title);25 contentFrame.Navigate(selectedItem?.PageType);26 }27 {28 navigationView.SelectedItem = navigationView.MenuItems[0];29 contentFrame.Navigate(typeof(Home));30 }31 }32 private void NavigationHelper_SaveState(object sender, SaveStateEventArgs e)33 {34 var selectedItem = navigationView.SelectedItem as NavigationViewItem;35 var item = SampleData.AllItems.First(i => i.Title.Equals(selectedItem?.Content));36 e.PageState["Selected"] = item;37 }38 }39}
NavigationHelper
Using AI Code Generation
1using AppUIBasics.Common;2using Windows.UI.Xaml.Controls;3using Windows.UI.Xaml.Navigation;4{5 {6 public Page1()7 {8 this.InitializeComponent();9 }10 protected override void OnNavigatedTo(NavigationEventArgs e)11 {12 base.OnNavigatedTo(e);13 NavigationHelper.OnNavigatedTo(e);14 }15 protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)16 {17 base.OnNavigatingFrom(e);18 NavigationHelper.OnNavigatingFrom(e);19 }20 }21}22using AppUIBasics.Common;23using Windows.UI.Xaml.Controls;24using Windows.UI.Xaml.Navigation;25{26 {27 public Page2()28 {29 this.InitializeComponent();30 }31 protected override void OnNavigatedTo(NavigationEventArgs e)32 {33 base.OnNavigatedTo(e);34 NavigationHelper.OnNavigatedTo(e);35 }36 protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)37 {38 base.OnNavigatingFrom(e);39 NavigationHelper.OnNavigatingFrom(e);40 }41 }42}43using AppUIBasics.Common;44using Windows.UI.Xaml.Controls;45using Windows.UI.Xaml.Navigation;46{47 {48 public Page3()49 {50 this.InitializeComponent();51 }52 protected override void OnNavigatedTo(NavigationEventArgs e)53 {54 base.OnNavigatedTo(e);55 NavigationHelper.OnNavigatedTo(e);56 }57 protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)58 {59 base.OnNavigatingFrom(e);60 NavigationHelper.OnNavigatingFrom(e);61 }62 }63}64using AppUIBasics.Common;65using Windows.UI.Xaml.Controls;66using Windows.UI.Xaml.Navigation;67{
NavigationHelper
Using AI Code Generation
1NavigationHelper.NavigateToPage(typeof(2));2NavigationHelper.NavigateToPage(typeof(1));3NavigationHelper.NavigateToPage(typeof(1));4NavigationHelper.NavigateToPage(typeof(1));5NavigationHelper.NavigateToPage(typeof(1));6NavigationHelper.NavigateToPage(typeof(1));7NavigationHelper.NavigateToPage(typeof(1));8NavigationHelper.NavigateToPage(typeof(1));9NavigationHelper.NavigateToPage(typeof(1));10NavigationHelper.NavigateToPage(typeof(1));
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!