Hide application in the OnBackButtonPressed event - c#

I have 2 pages. LoginPage and ListPage.
In the LoginPage I ask for the credentials and the stores.
Then I see a list of information in ListPage.
What I want to get is that when I press the back button and capture the OnBackButtonPressed event, I want the application to hide and not return to the LoginPage page.
How can I do this?
Thank you very much for the help.

Instead of using NavigationPage you should directly be setting the MainPage for Navigation if you do not want to go back:
Application.Current.MainPage= new ListPage();
Or in the existing flow, you can close the current window in onBackPressed:
System.Diagnostics.Process.GetCurrentProcess().CloseMainWindow();
Or if you want to kill the process you can
System.Diagnostics.Process.GetCurrentProcess().Kill();

Related

Xamarin Forms modal navigation

I have a section in my app that requires a modal navigation stack different from the main one.
I push modal a new navigation page
await App.Current.MainPage.Navigation.PushModalAsync(new NavigationPage(new FlightPage())
and after selecting an item i push a new page on the stack
await App.Current.MainPage.Navigation.PushModalAsync(new LegDetailsPage(this))
i can start this process from the login page or from the shell, the login is set by the App.xaml.cs with new NavigationPage(new LoginPage()).
Problem is by starting this process from the login page, the back navigation button is not seen, but from the shell it is.
This is what starting from shell looks like
This is what starting from login looks like
When pushing from the login the modal page appears from the bottom but when pushing from the shell it appears from the center like it should.
Tried removing the login page as a navigation one but still didn't work
By design. Are you sure you want a modal page?
1) A modal page is, well, modal. Use it when user is supposed to complete some task, then press some button to indicate they are done. AFAIK, iOS/Android apps don't usually show a "back button" for a modal page. Consider "Cancel" and "Done" buttons at page bottom.
2) When using NavigationPage, await Navigation.PushAsync would show back arrow. That's similar to a browser's stack of pages.
If you use PushAsync instead of PushModalAsync, and still don't see a back arrow (and optional page title), then your page isn't showing the navigation bar. See any NavigationPage example.
we have option to enable and disable back button from particular page.if you want to disable back button make it false as shown below
await Navigation.PushModalAsync (new LoginPage(), false);
for more info refer this documentation
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/modal

Invoke Root Frame control for Refresh

Need to refresh Root frame control once network is disconnected in terminal.
Steps:
If login successful, it redirect to Home page.
Inside home view, child frame set to navigate to another page, but home view is act as master page, it constant.
Now I accessing any child page, but in between if network is disconnected, then it should notify to home view control for status color change.
Can any one suggest.
You should tell us which part is confusing that makes you cannot finish your task. Here are something related:
I have no idea why network status changed is related to child and main frame. Personally I would register the NetworkStatusChanged event to detect the network status.
I'm not so sure whether you've noticed the official sample. In any official sample you can find this code:
rootPage.NotifyUser
Actually the NotifyUser method is defined in mainpage and then in the demo page you will call the following code(A simple demo):
MainPage rootPage = MainPage.Current;
So if your network changes, you just need to detect the event and then call the rootframe's method to change the color.
https://msdn.microsoft.com/en-us/magazine/jj694937.aspx
Using MVVM Messenger concept, it help to Send back to my parent page control to refresh.

Switching from one window to another in WPF and making it active

I'm pretty new to WPF and I'm trying to make a database system. What I currently have is a Login Window. When you enter the user and password you are supposed to go to another window StudentInfoSystem . The code I used is pretty basic and common.
var info = new StudentInfoSystem.MainWindow();
info.Show();
this.Close();
So, what this would do, is after you press the login button, you get transferred to StudentInfoSystem and the login window closes. The problem I have with Show() is that it opens a window and immediately returns, right? It doesn't wait for the new window to close. So, my question is how can I open a new window and WORK with it? When I say work, I meant to show out information in my textboxes (In the NEWLY opened window) depending on the role the user has, etc...
I'm guessing the above code is in the button click handler for the Login Window, which would make the Login Window the parent of the StudentInfoSystem window.
Since WPF will close the parent and any child(ren) window(s) when closing the parent window, your StudentInfo window will also close when calling
this.Close();
One option might be to instead call
this.Hide();
but without seeing how the rest of your app is set up, not 100% sure this is the best approach.
Perhaps see these SO questions:
wpf-create-sibling-window-and-close-current-one
how-to-close-current-window-in-code-when-launching-new-window
Try window.Activate() to focus the new window and/or [any element].Focus() to focus any element within window.
As I understand, this should do what you want:
info.ShowDialog();
You could also check ShutdownMode property. I would rather say, login window is sth you want to close after login, but do what you want :). Usage of ShutdownMode property:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
this.ShutdownMode = System.Windows.ShutdownMode.OnLastWindowClose;
}
}

ASP.NET WebForms WebSite - controls changes their's values in codebehind but not on frontend

I will try my best to express what I do not understand about WebForms. Maybe somone can explain it to me....
I work in 'quite big' WebForms (website) Application.
Application already has a PopUp (which I HAVE TO USE, because I dont have time to make a new one) like MessageBox in Winforms, but:
it's place is in MasterPage.master (I use it like ((MasterPage)Poup.Show("blablabla", yes_no));
I can add buttons to it and change style etc.
it doenst stop application (like .ShowDialog() in WinForms), so I have to assign onClick events dynamicly and assign/catch them on Page_Load to go to the wanted method depending on users input on form. At the moment i can't to anything about it.
And here is the problem:
Depending on form validation, if users press a button (on a form) - then form realods it's TextBox.Text's values and changes DropDownLists's SelectedIndexes and SelectedValues.
BUT IF YOU GO TO THE SAME METHOD WITH MY POPUP WINDOW:
ex: Do you confirm? YES/NO
If you press You press ANY button, then: CHANGES ARE VISIBLE BY CODEBEHIND BUT TEXTBOXES ARE STILL VISIBLE WITH PREVIOUS DATA ON THE SCREEN, ALSO DROPDOWNLISTS HAVE OLD VALUES SELECTED
BUT IF YOU PRESS A FORM BUTTON (WHATEVER WHICH), EVEN IF IT'S METHOD DOES NOTHING - ALL FORM WILL "RELOAD" AND HAVE PROPER DATA ON THE SCREEN.
(it's not about Runat="server" or AutoPostBack, I checked it)
I dont event know what to do about it :(
Update panels are used to partial refresh of some fields inside him, caused by certain triggers, like buttons, textchanged, etc.
See more about update panel's:
https://msdn.microsoft.com/en-us/library/bb399001.aspx
http://www.asp.net/web-forms/overview/older-versions-getting-started/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers
http://www.asp.net/ajax/documentation/live/tutorials/IntroductionUpdatePanel.aspx
(Haven't worked with web forms events in a while, just answering in case nobody else does.)
Out of curiosity, what happens if, in your javascript handler for your popop button, you getElementById one of the form buttons on the main page and call ".click()" on it?
The basic problem sounds like there's a runat/server form on the main page, with certain behaviors associated with it, which is submitted by the main page runat server buttons but not by your popup JS.
Easy enough to test with the above approach. If that works, take a step further and try to figure out why it worked, based on what those buttons are doing.
(If you're not using JS at all for the popup, then View Source the output HTML, because I'm sure it is. Backtracking those calls should help you understand the trace from popup button press to form submission.)
I probably mislead you by "OnClick", it's NOT javascript OnClick="method()" issue.
I mean ClickEvent on a button (in codebehind). For Ex. If form is validated I have to do:
ViewState["PopUpSelection"] = "yes_no";
(MasterPage)PopUp.Show("blabla",yes_no) //loads popup from MasterPage;
return;
then on Page_Load I have:
**if (string)ViewState["PopUpSelection"] == "yes_no"
{
ButtonConfirmYes.Click += new EventHandler(MyMethod);
}**
And if method "MyMethod" is called from a FORM button, everything "will go ok".
If you call the same method from PopUp button: changes are visible by codebehind, but on the screen nothing happens, unless i press ANY FORM BUTTON, whatever it does

How to implement a login/register flow in windows phone 8

I'm trying to implement the login/register/forgot password flow for my first app in windows phone.
The idea main points of the result are:
The login form is accessible from many points of the app, when the user attempts to make an action that requires him to be logged in the system.
The login form must show the "register" option, showing a new screen with the register form
When the user closes the register form must return to the login form
A) I explored the Add/New Item menu in Visual Studio and the Content Dialog seems to be prepared for that functionallity, since its template xaml is a login screen. So I created a LoginDialog and a RegisterDialog from the ContentDialog template. Am I right?
B) The "sign in" button closes immediatly the Dialog, whats is the common pattern to make the user wait while the request is sent across the network and show the possible errors that may happen
C) How should I implement the navigation between ContentDialogs by the way I added a button to the LoginDialog:
private async void RegisterButton_Click(object sender, RoutedEventArgs e)
{
this.Hide();
await new RegisterDialog().ShowAsync();
}
How can I make the RegisterDialog to return to the Login dialog on close?
D) The dialog get closed when I press the Primary or Secondary button. How can I avoid it to close to show validation errors (like invalid password)
In my application I implemented it by putting both the Sign in option and the Register option on a MessageDialog, which is shown when the user tries to log in, so you don't need to put the Register option on the Sign in page.
I added separate pages, not content dialogs. I think it's a better approach, because this way if you get an error, the page won't "close", like a ContentDialog does, and you can handle the navigation very easily with simple GoBack and Navigate calls.

Categories

Resources