Xamarin Forms modal navigation - c#

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

Related

Hide application in the OnBackButtonPressed event

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();

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

Accessing SplitView control from a different page than it's host - C# XAML Windows 10 UWP

Pre-warning, I'm new to C# and XAML, but I'm really enjoying Windows 10 UWP apps. I've got a question on how to appropriately handle a SplitView.
I've got a Main Page, in which I have a SplitView control. In the SplitView Content, I've added a Frame for navigation to other pages. I want to add the Hamburger button on the child page to open the SplitView on the Main Page, but I can't access the SplitView control from the child page. How can I make the SplitView control accessible so that the hamburger button within the sub-page can open the SplitView pane?
The alternative is to add a header in the Main Page and have a static hamburger button there, but I don't like this option as it makes handling the text header content more difficult. Another is to copy the SplitView to each page. I don't want to do this either.
Any advice would be fantastic! Thank you.
I would highly recommend you take your alternative option of including the hamburger button in the main page. Users always expect it to be in the same location every time and changing this approach will probably result in a bad user experience.
You also don't want to be repeating code and thus you don't want to recreate the button on every page as well as any additional functionality like the open/close commands.
Rather than referencing elements from one page to another, a better practice is to keep things loosely coupled. This can be done with a messenger plugin which sends an event from one page to the other which can give it instructions on what you want to do. That way the other page only has to listen for the event instead of holding strong references. To streamline some of this process you could inherit from a base class which implements the messenger functionality.
That would provide a solution to your button and your header text situations but setting them up is out of the scope of this question. Depending on the size of you app and your goals, you might like to look into existing frameworks which helps in designing maintainable apps. A good Mvvm framework I would recommend checking out is MvvmCross which also cross platform and contains a messenger plugin.
Good luck with your app.
I found that solution :
In the MainPage, in your SplitView pane button method, add a SplitView reference as parameter in Navigate() :
private void SlitViewPaneButton_Tapped(object sender, TappedRoutedEventArgs e)
{
var frame = contentFrame;
Page page = frame?.Content as Page;
if (page?.GetType() != typeof(ChildPage))
{
frame.Navigate(typeof(ChildPage), SplitViewName);
}
}
In your ChildPage.xaml.cs :
protected override void OnNavigatedTo(NavigationEventArgs e)
{
SplitView sv = new SplitView();
sv = e.Parameter as NavigateControls;
}
You can now do sv.IsPaneOpen = false, in your ChildFrame code.
Note : if you want to pass several Controls, create a Class with these Controls as variables, and use an instance as parameter.
As stated above, it is better to keep your hamburger button in your main page for a couple of reasons. One is the consistency mentioned above. Second, you would have to recreate the hamburger button in each of your content pages instead of just once in the MainPage.xaml. Additionally, keep in mind, there are different kinds of interactions with the SplitView menu in terms of how it pops in and out and how it is displayed, all listed below.
Inline – When the menu pane is opened, it pushes the content over. When it’s closed, the content goes back to its original location
Overlay – When the menu pane is opened, it lays on top of the content. When it’s closed, it is invisible.
Compact Overlay – When the menu pane is opened, it lays on top of the content. When it’s closed, the pane is still visible in Compact Mode.
Compact Inline – When the menu pane is opened, it pushes the content over. When it’s closed, the content goes back to its original position but the pane is still visible in Compact Mode.
You can also see a quick intro into the SplitView here.
http://jamesqquick.com/windows-10-splitview-intro/

ProgressIndicator wraps content on page

Im creating an app where the startpage is an login screen. When user enter their credentials and finally taps the login button an Progressindicator Dialog is being shown. The dialog is based on an Window Popup. The window and the indicator works like a charm but there is one problem. The indicator is wraping the content on the page. So if you for example entered the wrong credentials and tapped the login button the inticator will dissapear to give the user one more chance to enter their right credentials. But when the indicator dissapear the Rememember Me Checkbox position is changed, it's getting placed over the login button. It seems like the Indicator Dialog is wraping the content on the page. Im a pretty good css & html developer so i wonder if there are something like in css called z-index or is it possible to set the position of the checkbox to absolute so its position aren't based upon other elements position. I used this guide to make this indicator.
http://blogs.msdn.com/b/priozersk/archive/2010/09/20/creating-progress-dialog-for-wp7.aspx
Thanks
Problem solved. As i copied the sample code from the orginal project to my own there was a few variables that i had to change the value of to work with my project. Including the height and the width of the object and so on. Anyway, it works like a charm now.

Overlapping Window/Page or Custom messagebox?

I want to preface this by saying I'm a noob with WPF/.net programming.
Here is my question that requires a bit of guidance. I have a window and I load pages in and out as my navigation. On one particular page, when the user clicks on one of the items (button for example), I need to display a small form to gather more information. I'm not sure what the best approach is... what I would love (but do not know where to begin even searching for this solution) would be to open a popup balloon style window with a few textboxes and a submit button.
Other options I've explored would be to use a separate page. Save off the current page and load a new page with these textboxes and a submit button. Or to use a custom messagebox instead (least favorite option).
I would like this new extra info page to blend in with rest of the app so that the main page is still visible in the background. Any suggestions??
You can use WPF's Popup control
<Popup>
<!-- Your Content Here -->
</Popup>
Personally I have issues with WPF's Popup, so have my own custom UserControl that works like a Popup.
I ended up using modal window (ShowDialog) method for this.

Categories

Resources