How to close the current Activity when user click Back button - xamarin

In my project, I have implemented the MvvmCross to display fragment as page.
I have a Main Menu page which has Left drawer. It is defaulted to show Main Page as fragment.
In the main page, I have a drop-down menu in its action-bar. It will launch the respective page when user clicks an item
User clicks an item and it launches the Company info page.
Now, the Company info page is the current page being displayed.
Problem :
How to close the current display page which is company info page when user click the back button? When this page is closed, the main page will be seen.
where to write the logic to handle the back button ?
In Main Menu.cs or Main Page.cs or Company info.cs
public override void OnBackPressed()
{
}

You can call the finish(); method of the activity. Do this in your 'Company' activity. That will close the current activity and returns to the previous (as far as I know).
More Infos about the method: Xamarin Developer

Related

Xamarin Page Navigation (again)

We're starting on a Xamarin.Forms app, and there are going to be quite a few pages and the navigation between pages will be handled completely by the app - specifically there is no back button, which shouldn't be a problem since we are only planning on releasing for iOS.
The first page the user encounters is the Login page, once logged in they go to the Home page. To perform this transition I just call
LoginPage.Navigation.PushModalAsync(HomePage)
and that's fine.
Now if, on the Home page, they press the Logout button, I could call PopModalAsync(), the problem is that the Logout button exists on all the pages, so the user could have followed a path like this:
Login -> Home -> Create -> Format -> Print -> Logout
and I need to immediately jump to the Login screen.
So on the Home page, if the user presses the Logout button, I tried calling
ApplicationHomePage.Navigation.PushModalAsync(LoginPage);
but got an exception:
System.InvalidOperationException: Page must not already have a parent.
So just for fun I thought I'd try the easy solution:
LoginPage.Parent = null;
ApplicationHomePage.Navigation.PushModalAsync(LoginPage);
I'm never going to have a back button, and the iPad doesn't have one, so the contents of the navigation stacks aren't really important (right?)
Is this method of navigating "legal"? Is it going to cause me some problem I'm not seeing right now?
I think you can take a look to this
You should don't add your login page to a NavigationStack. Change MainPage property is a good solution...

Refresh a Fusion block on click of a button wordpress Avada

I have some buttons on a page and on click of each button the page gets reload and the data changes. Now, I would like to refresh that particular fusion block only without reloading the page. The buttons are added to the page as a widget (with some valid reasons) and the fusion block is on the page itself. Would it be possible to achieve what I am looking for?

Replace Xamarin forms page without pushasync

I've searched through numerous online posts and can't find a suitable answer for this scenario. It's a pretty common requirement. I have a Xamarin.Forms app with a login page and listing page. When the app is started, the login page is displayed. When they login successfully, I want to display the listing page and prevent them from backing up by clicking on the toolbar back button or the hardware back button.
Change the MainPage
when you start the app you should have
Application.Current.MainPage = new LoginPage();
after login, something like
Application.Current.MainPage = new MyFirstPageAfterLogin();

Disallow closing Rg Plugin popup in Xamarin Forms

I am using Rg Plugin popup for popup in Xamarin Forms application. I would like to disallow user from closing this popup. After some time, application will close this popup. Is it possible?
Why I need this: When user opens application for the first time, I would like to show usual start page and on top of it popup. Both are visible: in the middle there is popup and around it usual start page with grey overlay. In popup progress bar will be displayed while fetching data from server. User should not be able to close this popup. When fetching data is over, I would like to refresh start page and close this modal.
As Dinesh kumar pointed out, 2 things need to be done - to disallow clicking on background and to disallow back button:
public MyPopup()
{
InitializeComponent();
CloseWhenBackgroundIsClicked = false;
}
protected override bool OnBackButtonPressed()
{
return true; // Disable back button
}

Wicket: Modal Windows and callback functionality

I have a modal window that shows a panel which contains a form that has some textfields and a submit button
on submit an insert into the database occurs and then I have some ajax behaviour that i want to activate on the modal windows containing page on click of the button.
So flow is at present:
click link
modal window appears
user fills out form
user submits form
form data persisted to db
modal window closes
I need it to do this in addition:
activate some ajax behaviour on the page that contains the panel
any help on how best to do this in the wicket way is appreciated.
I resolved this by passing an instance of the page containing the panel to the panel (i.e. - in the constructor), then calling a method on the page from the panel to perform the Ajax update.
I would be interested to see what others have done or to hear if there are issues with the approach I have taken.
Set up a WindowClose callback.
In the WicketStuff project called ModelX (Disclaimer: I'm the developer of that) I have created an IWindowClosedListener interface which has a method:
void windowClosed(Panel panel, AjaxRequestTarget target)
So then any Page or Panel that can open a modal that needs to do something when that modal is closed simply implements that interface and its windowClosed method gets called at the right time.

Resources