I have navigated from a ContentDialog to a Page in my UWP app written in C#. Now I want to return back to the ContentDialog when I click a button on the Page.
I tried writing (Window.Current.Content as Frame)?.GoBack(); but that only returned to my MainPage (from where my ContentDialog was launched).
If it is possible to perform such an action, what is the correct syntax?
No, you can not navigate to or even from content dialog. What you do is that you are navigating between the pages. Action that you call in your dialog does invoke this navigation i.e. there would be no difference if it was done with button or button in content dialog - these are just controls on your page.
If you want to see the dialog on MainPage when you navigate back, implement the logic to show it again if certain conditions are met (for example pass NavigationEventArgs containing details whether Content Dialog should be re-opened).
Related
I have a problem/question?
I created a button in my custom navigation menu, so when I click the button it goes to for example Page1. But now I only want to make the button active if the current active page not is equal to Page1. Is this possible and how?
If I understand correctly, you want to disable the button when Page1 is being displayed.
Most, if not all, Xamarin Forms controls have an IsEnabled property, so you want to set this to false when Page1 appears, and to true when it disappears. A ContentPage has onAppearing and OnDisappearing virtual methods that you can override to run code when the page appears and disappears respectively.
However, context matters. Knowing absolutely nothing about how you have set up your custom navigation menu, I cannot say exactly how you can do this. Is a reference to the button available in the ContentPage's OnAppearing method? If not, you need some way to get a reference to the button, or if the button is using bindings, to the view model that the button is binding to (which assumes you are using a binding for the IsEnabled property of the button), to set the appropriate property to disable/enable the button.
EDIT: Oh and see your actual question was if you can see the current active page. You can check Application.Current.MainPage to see what page is currently active, but if it is a NavigationPage, then you would have to retrieve the last page in the navigation stack to see what page is actually being displayed. Likewise for any other "container" page, like a TabbedPage, you would have to see what page the container page is actually displaying. For a TabbedPage you would have to check the currently selected tab and get the page that is being displayed there, and then if this is a NavigationPage the you have to, again, check the stack for the last page.
Project and problem explanation
In my case I have a page which instructs the user how to move a certain machine. This page is supposed to be a modal page since the page should not be navigated away from without performing or completely canceling the action.
I have a mainpage with a listview which opens the details page of any of the items contained in the listview on click through the onSelect method:
Navigation.PushAsync(new FooPage(string Name)); /* gets called in the
onSelect method if selection is not null*/
The model is retrieved within the details page's viewmodel after passing the name to it and then using a model manager injected into the viewmodel with Unity to retrieve it.
-- we now both have a mainpage and detailspage on the stack which of only the detailspage has a backbutton --
On the detailspage we have a button called "Teach" with a x,y,z field next to it after clicking it this method gets called:
private async Task Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushModalAsync(new ManualTeachPage());
}
which then, as it should, creates the page but then for some reason decides to add a back button to it:
Debugging and Research
This behavior is not visible on Android which does not have a visible back button or navigation bar on this page but does have a backbutton on the Details-page as well.
I have used modal pages before but I have never seen this kind of behavior, I have tried using the Navigation property of the Application.Mainpage itself which resulted in the exact same result except for one case.
I thought it might have something to do with me switching out the Application.Mainpage at one point(there is a stack of tutorial pages the user has to go through), seems like calling the pushModalAsync one line AFTER setting the new mainpage then it DOES push the page as a modal page and performs like one (without a back button) but does not do so after this point.
No bug reports on Bugzilla about this either as far as I have seen, neither have I found anything on the internet about this particular problem.
Note that when clicking the back button on the teachPage it returns to the detailspage. When the teachPage gets pushed it does actually get pushed onto the ModalStack.
update 1
Checked again if the modal page which I was talking about was the only modal page on the modal Stack, it was. NavigationPage.SetHasBackButton(this, false); does not seem to work either as suggested by Diego Rafael Souza.
update 2
I thought I would temporarily disable the backbutton by using the onBackButtonPressed within the teachpage until I had found a solution. Turns out this doesn't work for UWP anymore, this method does not get called anymore on this page or any page for that matter. It does work for the Android Hardware button though.
update 3
I tried using:
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
AppViewBackButtonVisibility.Collapsed;
This does hide the backbutton on UWP but for some reason #if WINDOWS_UWP doesn't work at all. If I do this without the #if the program won't build for Android. No solution yet, not only this but when using this fix the other pages still had the onBackButtonPressed method disabled.
update 4
after updating to the newest version of xamarin forms the OnBackButtonPressed started working again. The backbutton still appears on the page but I now have disabled it.
Recreating the problem
I recreated the problem in this small test project:
https://www.dropbox.com/sh/6btsud3uvw503ee/AAAiaGb3TwhMrZMJb2j-rd36a?dl=0
In your function Button_Clicked() in your example, in page DetailPage, where you call your Modal, right after calling PushModalAsync(new TeachPage());, use:
NavigationPage.SetHasNavigationBar(this, false);
NavigationPage.SetHasBackButton(this, false);
My guess is when you tried using the above SetHasBackButton, you were doing it on the Modal itself, but the back button you were actually seeing came from your DetailPage.
Once you add this, the modal pops up, and the back button disappears. If you set a "Back" button on your modal in order to close it, you can easily get your NavBar and BackButton back in your DetailPage by adding in an OnAppearing() Function in your DetailPage code-behind like so:
protected override void OnAppearing()
{
base.OnAppearing(); // do the usual stuff OnAppearing does
NavigationPage.SetHasNavigationBar(this, true); //get your navbar back
NavigationPage.SetHasBackButton(this, true); //get your back button back
}
In summary, I do have a modal dialog in Catel, invoked with:
_uiVisualizerService.ShowDialog(viewModel)
Inside that dialog, I do a long process showing a Wait Service:
_pleasewaitservice.Show();
// HARD WORK here
_pleasewaitservice.Hide();
And Then I invoke another modal dialog.
_uiVisualizerService.ShowDialog(configureViewModel)
However, when I click outside of the application while it is doing the hard work (when the pleasewaitservice is shown), the second modal dialog is displayed behind the main application, so I cannot focus the Window because it is behind and it is modal. I have to close the app from the task killer.
After checking it carefully, I realized that origin is the pleaseWaitService. If I don't show it, the second modal dialog is always displayed correctly.
Does anyone have any hint about how to solve it?
I was googling about how to force to set focus in any Window, but I didn't find anything.
Thanks
Regards
Saul Hidalgo.
You might want to try the BringWindowToTop extension method inside the code-behind of the window:
https://github.com/Catel/Catel/blob/46fcc69575e533eb9e02669ebaa2246894dc98d8/src/Catel.MVVM/Catel.MVVM.Shared/Windows/Extensions/WindowExtensions.cs#L237
I am learning ASP .NET and came across modal popup extender. I found that animations are possible with modal popup but I have a question as to what is the difference between OnShowing and OnShown tags. A google search gave me
OnShowing – Called before the modal popup is shown.
OnShown – Called after the modal popup is shown.
OnHiding – Called before the modal popup is hidden.
OnHidden – Called after the modal popup is hidden.
But, I am confused about something. When I click on the target button and use OnShowing, there is no animation effect. But when I use OnShown, the animation is successful. Now, isn't the OnShowing called BEFORE the modal popup is shown, so when I Click on the target button, it is the function OnShowing which is supposed to be called. I think I am missing something here. Thanks for the help!
Have you checked this [AnimationExtender with ModalPopup] (http://forums.asp.net/p/1318051/2624063.aspx#2624063) ? They provided a really nice sample for ModalPopUpExtender Animations. It will give you a true understanding on your concern.
Hope it helps you.
Try returning true by adding return true; on onshowing function
I'm taking a whack at WPF and trying to learn as I go. I'd appreciate any advice offered.
I've got a Window that has a Page attached to it (through a Frame on the Window). When you press a button on the Page, I want a custom window to pop up to present several custom options and be displayed in a manner of my choosing (I'm thinking right now I want it to be a grid but that may change as I go on). When selected, the modal window will disappear and return to the calling method (button press from the Page) the value of the selected choice.
I don't want the standard windows dialog box with the options of yes, no, okay, cancel, or anything like that. This is truly just a custom popup that returns a value to the caller when the user makes their selection on the popup.
Create a new Window subclass, which you can layout however you like. Then in your button click event handler, display it modally using myModalWindow.ShowDialog();. You can then have a property on the window class which you can access after it closes in order to access result data, i.e.:
myModalWindow.ShowDialog();
var data = myModalWindow.SomeResultProperty;
If you really want to have something returned from a method, I suppose you could create your own public method on your window class which internally calls ShowDialog() and then returns a value.