Best WinAppDriver code snippet using AppUIBasics.Common.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}...
InterviewPage.xaml.cs
Source:InterviewPage.xaml.cs
...34 /// within the group.35 /// </summary>36 public sealed partial class InterviewPage : Page37 {38 private NavigationHelper navigationHelper;39 private ObservableDictionary defaultViewModel = new ObservableDictionary();40 Interviewer.Data.configuration configuration;41 /// <summary>42 /// NavigationHelper is used on each page to aid in navigation and 43 /// process lifetime management44 /// </summary>45 public NavigationHelper NavigationHelper46 {47 get { return this.navigationHelper; }48 }49 /// <summary>50 /// This can be changed to a strongly typed view model.51 /// </summary>52 public ObservableDictionary DefaultViewModel53 {54 get { return this.defaultViewModel; }55 }56 public Interviewer.Data.configuration Configuration57 {58 get { return configuration; }59 set { configuration = value; }60 }61 public InterviewPage()62 {63 this.InitializeComponent();64 this.navigationHelper = new NavigationHelper(this);65 this.navigationHelper.LoadState += navigationHelper_LoadState;66 //controlsSearchBox.SuggestionsRequested += SearchResultsPage.SearchBox_SuggestionsRequested;67 }68 //private async void controlsSearchBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)69 //{70 // var groups = await AppUIBasics.Data.ControlInfoDataSource.GetGroupsAsync();71 // var suggestions = new List<ControlInfoDataItem>();72 // foreach (var group in groups)73 // {74 // var matchingItems = group.Items.Where(75 // item => item.Title.Contains(sender.Text));76 // foreach (var item in matchingItems)77 // {78 // suggestions.Add(item);79 // }80 // }81 // controlsSearchBox.ItemsSource = suggestions;82 //}83 //private void controlsSearchBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)84 //{85 // var itemId = (args.SelectedItem as ControlInfoDataItem).UniqueId;86 // this.Frame.Navigate(typeof(ItemPage), itemId);87 //}88 /// <summary>89 /// Populates the page with content passed during navigation. Any saved state is also90 /// provided when recreating a page from a prior session.91 /// </summary>92 /// <param name="sender">93 /// The source of the event; typically <see cref="NavigationHelper"/>94 /// </param>95 /// <param name="e">Event data that provides both the navigation parameter passed to96 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and97 /// a dictionary of state preserved by this page during an earlier98 /// session. The state will be null the first time a page is visited.</param>99 private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)100 {101 var config = await InterviewerDataSource.GetConfiguration();102 Configuration = config;103 MainViewModel.ViewModel.SelectedConfiguration = config;104 this.DataContext = MainViewModel.ViewModel;105 } 106 private void SearchBox_QuerySubmitted(SearchBox sender, SearchBoxQuerySubmittedEventArgs args)107 {108 //this.Frame.Navigate(typeof(SearchResultsPage), args.QueryText);109 }110 #region NavigationHelper registration111 /// The methods provided in this section are simply used to allow112 /// NavigationHelper to respond to the page's navigation methods.113 /// 114 /// Page specific logic should be placed in event handlers for the 115 /// <see cref="GridCS.Common.NavigationHelper.LoadState"/>116 /// and <see cref="GridCS.Common.NavigationHelper.SaveState"/>.117 /// The navigation parameter is available in the LoadState method 118 /// in addition to page state preserved during an earlier session.119 protected override void OnNavigatedTo(NavigationEventArgs e)120 {121 navigationHelper.OnNavigatedTo(e);122 }123 protected override void OnNavigatedFrom(NavigationEventArgs e)124 {125 navigationHelper.OnNavigatedFrom(e);126 }127 #endregion128 }129}...
NavigationHelper
Using AI Code Generation
1using AppUIBasics.Common;2using Windows.UI.Xaml.Controls;3using Windows.UI.Xaml.Navigation;4{5 {6 public Scenario1()7 {8 this.InitializeComponent();9 }10 private NavigationHelper navigationHelper;11 {12 get { return this.navigationHelper; }13 }14 protected override void OnNavigatedTo(NavigationEventArgs e)15 {16 navigationHelper.OnNavigatedTo(e);17 }18 protected override void OnNavigatedFrom(NavigationEventArgs e)19 {20 navigationHelper.OnNavigatedFrom(e);21 }22 }23}24 <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">25using AppUIBasics.Common;26using Windows.UI.Xaml.Controls;27using Windows.UI.Xaml.Navigation;28{29 {30 public Scenario1()31 {32 this.InitializeComponent();33 }34 private NavigationHelper navigationHelper;35 {36 get { return this.navigationHelper; }37 }38 protected override void OnNavigatedTo(NavigationEventArgs e)39 {
NavigationHelper
Using AI Code Generation
1using AppUIBasics.Common;2using Windows.UI.Xaml.Controls;3using Windows.UI.Xaml.Navigation;4{5 {6 public Scenario1()7 {8 InitializeComponent();9 }10 protected override void OnNavigatedTo(NavigationEventArgs e)11 {12 NavigationHelper.OnNavigatedTo(e);13 }14 protected override void OnNavigatedFrom(NavigationEventArgs e)15 {16 NavigationHelper.OnNavigatedFrom(e);17 }18 }19}
NavigationHelper
Using AI Code Generation
1using AppUIBasics.Common;2using Windows.UI.Xaml;3using Windows.UI.Xaml.Controls;4using Windows.UI.Xaml.Navigation;5{6 {7 public NavigationViewPage()8 {9 this.InitializeComponent();10 NavigationHelper = new NavigationHelper(this);11 NavigationHelper.LoadState += NavigationHelper_LoadState;12 NavigationHelper.SaveState += NavigationHelper_SaveState;13 }14 public NavigationHelper NavigationHelper { get; set; }15 private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)16 {17 }18 private void NavigationHelper_SaveState(object sender, SaveStateEventArgs e)19 {20 }21 protected override void OnNavigatedTo(NavigationEventArgs e)22 {23 NavigationHelper.OnNavigatedTo(e);24 }25 protected override void OnNavigatedFrom(NavigationEventArgs e)26 {27 NavigationHelper.OnNavigatedFrom(e);28 }29 }30}31using AppUIBasics.Common;32using Windows.UI.Xaml;33using Windows.UI.Xaml.Controls;34using Windows.UI.Xaml.Navigation;35{36 {37 public NavigationViewPage()38 {39 this.InitializeComponent();40 NavigationHelper = new NavigationHelper(this);41 NavigationHelper.LoadState += NavigationHelper_LoadState;42 NavigationHelper.SaveState += NavigationHelper_SaveState;43 }44 public NavigationHelper NavigationHelper { get; set; }45 private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)46 {47 }
NavigationHelper
Using AI Code Generation
1using Windows.UI.Xaml.Controls;2using Windows.UI.Xaml.Navigation;3using AppUIBasics.Common;4{5 {6 private NavigationHelper navigationHelper;7 public NavigationViewPage()8 {9 InitializeComponent();10 navigationHelper = new NavigationHelper(this);11 }12 protected override void OnNavigatedTo(NavigationEventArgs e)13 {14 navigationHelper.OnNavigatedTo(e);15 }16 protected override void OnNavigatedFrom(NavigationEventArgs e)17 {18 navigationHelper.OnNavigatedFrom(e);19 }20 }21}22using Windows.UI.Xaml.Controls;23using Windows.UI.Xaml.Navigation;24using AppUIBasics.Common;25{26 {27 private NavigationHelper navigationHelper;28 public NavigationViewPage()29 {30 InitializeComponent();31 navigationHelper = new NavigationHelper(this);32 }33 protected override void OnNavigatedTo(NavigationEventArgs e)34 {35 navigationHelper.OnNavigatedTo(e);36 }37 protected override void OnNavigatedFrom(NavigationEventArgs e)38 {39 navigationHelper.OnNavigatedFrom(e);40 }41 }42}43using Windows.UI.Xaml.Controls;44using Windows.UI.Xaml.Navigation;45using AppUIBasics.Common;46{47 {48 private NavigationHelper navigationHelper;49 public NavigationViewPage()50 {51 InitializeComponent();52 navigationHelper = new NavigationHelper(this);53 }54 protected override void OnNavigatedTo(NavigationEventArgs e)55 {56 navigationHelper.OnNavigatedTo(e);57 }58 protected override void OnNavigatedFrom(NavigationEventArgs e)59 {60 navigationHelper.OnNavigatedFrom(e);61 }62 }63}64using Windows.UI.Xaml.Controls;65using Windows.UI.Xaml.Navigation;66using AppUIBasics.Common;67{68 {69 private NavigationHelper navigationHelper;70 public NavigationViewPage()71 {72 InitializeComponent();
NavigationHelper
Using AI Code Generation
1using Windows.UI.Xaml;2using Windows.UI.Xaml.Controls;3using Windows.UI.Xaml.Navigation;4using AppUIBasics.Common;5{6 {7 public NavigationViewPage()8 {9 this.InitializeComponent();10 NavigationHelper = new NavigationHelper(this);11 NavigationHelper.LoadState += NavigationHelper_LoadState;12 NavigationHelper.SaveState += NavigationHelper_SaveState;13 }14 public NavigationHelper NavigationHelper { get; set; }15 private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)16 {
NavigationHelper
Using AI Code Generation
1using AppUIBasics.Common;2using Windows.UI.Xaml.Controls;3{4 {5 private NavigationHelper navigationHelper;6 public NavigationHelperPage()7 {8 this.InitializeComponent();9 this.navigationHelper = new NavigationHelper(this);10 }11 protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)12 {13 navigationHelper.OnNavigatedTo(e);14 }15 protected override void OnNavigatedFrom(Windows.UI.Xaml.Navigation.NavigationEventArgs e)16 {17 navigationHelper.OnNavigatedFrom(e);18 }19 }20}21using AppUIBasics.Common;22using Windows.UI.Xaml.Controls;23{24 {25 private NavigationHelper navigationHelper;26 public NavigationHelperPage()27 {28 this.InitializeComponent();29 this.navigationHelper = new NavigationHelper(this);30 }31 protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)32 {33 navigationHelper.OnNavigatedTo(e);34 }35 protected override void OnNavigatedFrom(Windows.UI.Xaml.Navigation.NavigationEventArgs e)36 {37 navigationHelper.OnNavigatedFrom(e);38 }39 }40}41using AppUIBasics.Common;42using Windows.UI.Xaml.Controls;43{44 {45 private NavigationHelper navigationHelper;46 public NavigationHelperPage()47 {48 this.InitializeComponent();49 this.navigationHelper = new NavigationHelper(this);50 }51 protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)52 {53 navigationHelper.OnNavigatedTo(e);54 }55 protected override void OnNavigatedFrom(Windows.UI.Xaml.Navigation.NavigationEventArgs e)56 {57 navigationHelper.OnNavigatedFrom(e);58 }59 }60}
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!!