open new page from nav drawer xamarin forms - c#

I'm working on a Xamarin Forms App. This App has a ContentPage as MainPage, this ContenPage has 2 buttons. One of them, after being clicked, shows a new Page (I'm using App.Current.MainPage = page;) and this new page has a Nav Drawer.
The Nav Drawer shows perfectly, and all its pages work fine, but what I want to do is open a new page (lets call it "events") from one of this nav drawer pages. Every time a Nav Drawer Item is clicked, I use the code above:
if (menu == null)
return;
Page displayPage = (Page)Activator.CreateInstance(menu.TargetType); //the error shows here after trying to open my "events" page
Detail = new NavigationPage (displayPage);
menuPage.Menu.SelectedItem = null;
IsPresented = false;
But then, on my Nav Drawer Page, I'm trying to open my "events" page, but I don't know how to open it. I tried to use Navigation.PushAsyng(page) or App.Current.MainPage = page; but none of those work. Everytime I try to open it, this Unhandled Exception shows
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation
I use this reference for creating my nav drawer https://syntaxismyui.com/xamarin-forms-masterdetail-page-navigation-recipe/
So, does someone know how to solve this problem and open my "events" page? I've been trying to do this for a long time without any results.
Thanks!

Related

How to locate an element in new page using xpath after navigating to new page from old one in selenium?

I was trying to automate flipkart Login and adding product to cart. whenever i clicked on product its navigating to new page and not able to locate specified element(add to cart button) in new page. please help...The code i written is as follows...
webDriver.FindElement(By.XPath("//img[contains(#alt,'APPLE iPhone SE (Black, 64 GB)')]")).Click();//clicked on product
webDriver.FindElement(By.XPath("//button[#class='_2KpZ6l _2U9uOA _3v1-ww']")).Click();//navigating to new page
When a new tab is opened you should switch the Selenium driver focus to the new tab in order to access the elements there.
This can be done as following:
driver.SwitchTo().Window(driver.WindowHandles.Last());
When finished with that tab you will wish to close that tab and switch back to the first tab.
This can be done with
driver.SwitchTo().Window(driver.WindowHandlesLast()).Close(); // close the last tab
driver.SwitchTo().Window(driver.WindowHandles[0]); // get back to the first tab

Navigate to a Master details Page in Xamarin forms

Hello guys I am navigating to a master details page with this code:-
await Navigation.PushAsync(new MasterPage_Jobseeker());
But it is showing the back button instead the hamburger menu.
What should I do now?
Thank you!
Try turning the back button off on the NavigationPage.
var masterPage = new MasterPage_Jobseeker();
NavigationPage.SetHasBackButton(masterPage, false);
await Navigation.PushAsync(masterPage);
Although, I think if you're navigating to a MasterDetailPage you probably should be replacing the entire application main page with it to control the rest of your navigation from your MasterDetailPage.
Application.Current.MainPage = new MasterPage_Jobseeker();

Xamarin Forms - Menu issue when navigating from Content Page to MasterDetail Page

When trying to navigate from a Content Page to a MasterDetail Page the menu icon does not appear. Although, if i first load my MasterDetail Page the menu icon is there as tis supposed to be. The menu functionality is not affected. Working on Xamarin Forms but the problem occurs only when debugging in Android device.
Any idea about the icon?
Load instantly MasterDetail Page using MainPage = new NavigationPage(new MainPage())
Load from Content Page (LoginPage) using MainPage = new NavigationPage(new Login()) then when a button is pressed navigate to MasterDetail Page using await Navigation.PushAsync(new MainPage(), true);
Menus works on both cases
Changing from a content page to a master detail page is achieved by changing your navigation stack. You need to replace the MainPage to do this.
It's two different types of navigation.
You usually see this type of stack swap when navigating from a login page which is usually a simple content page to the main app landing page which can be a master detail page.
So rather than this
await Navigation.PushAsync(new MainPage(), true);
Do this
Application.MainPage = new MainPage();
If you are using an MVVM framework, this can best be achieved with a StackService injected into the View Model.
The MVVM framework I use, FreshMVVM, has the ability to swap out navigation stacks built in.
Follow this link then jump to the "Switching out NavigationStacks on the Xamarin.Forms MainPage" section for more details.

Set Root Page as Modal in Xamarin

I am building a Xamarin app, where in my portable logic, I have my app.cs file, launching a HomePage. At the moment this is done ith the following code:
public App ()
{
MainPage = new NavigationPage (new HomePage (Adapter, IsLoggedIn));
}
However, I don't want the "title" bar to show at the top of this page, so would like to launch this page with a PushModalAsync command, so that HomePage is a Modal Page. However, the following line doesn't work, as in app.cs, Navigation is not recognised.
Navigation.PushModalAsync(new HomePage());
Is this possible and if so, how do I get around this?
Thanks.
I don't believe you can set the root page of your App to be a modal. However, if you just want to hide the navigation bar, you can do this in the page you want it hidden on:
NavigationPage.SetHasNavigationBar(this, false);
Since it's your main page you can just set the page itself. Say "HomePage" inherits from "ContentPage":
MainPage = new HomePage (Adapter, IsLoggedIn);

I've opened a SSO popup, how do I click a link in the popup?

I'm accessing an SSO through an ASP/C# page and using the following code to open up a popup window:
string s = "window.open('" + getSSOlink(ah1.InstitutionUserID, cardnumber) + "','popup_window', 'width=980,height=600,resizable=yes');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
After opening the popup, I need to click 2 links deep into the the popup window navigate to a specific part of the page. The id on the first page is id25, and on the second page is cuRewardsLink, and it is the same every time the SSO opens. After the 2nd link is clicked, the user will be directed to a Rewards system.
I'm trying to find a way to open a new browser window that navigates automatically to the Rewards page. Ideally, they would not see the loading of the first two pages in the popup, just the final destination. The links within the popup do not have static URLs, there is an AJAX function returning information from the click(s) that create the link.
After the popup opens, I'm not sure how to access the HTML elements in the current browser window (the popup window). I tried using the WebBrowser class to navigate to the page, wait for loading,and click the links, but got a "ThreadState Exception - ActiveX Control cannot be instantiated because the current thread is not in a single thread apartment":
WebBrowser browser = new WebBrowser();
browser.Navigate(getSSOlink(ah1.InstitutionUserID, cardnumber));
Thread.Sleep(1000);
browser.Document.GetElementById("id25").InvokeMember("Click");
Thread.Sleep(1000);
browser.Document.GetElementById("cuRewardsLink").InvokeMember("Click");
browser.Visible = true;
Any help or thoughts would be appreciated,

Categories