Is there a way to set the ModalInPresentation value from Xamarin.Forms? I can set On<iOS>().SetModalPresentationStyle(UIModalPresentationStyle.FormSheet); on my ContentPage but I"m not able to prevent a dismiss of the page for specific cases as I would need it.
but I"m not able to prevent a dismiss of the page for specific cases as I would need it.
Generally,we can use ModalInPresentation = true; to prevernt the page be dismissed in page renderer.
public class CustomPageRenderer :PageRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
ModalInPresentation = true;
}
}
It works in Xamarin.iOS. However, it not works in Xamarin Forms now. I will check that where problem is.
I've uploaded a sample project here:
www.otherwise.com/ModalPresentation.zip
The MainPage just has a button that shows a modal panel via:
Navigation.PushModalAsync(new OTNavigationPage(new ModalPage()));
OTNavigationPage is a subclass of NavigationPage. I use it to set the modal presentation style:
On<iOS>().SetModalPresentationStyle(UIModalPresentationStyle.FormSheet);
There is also OTContentPage which exists only so I can have a native renderer to try to set the ModalInPresentation flag to true. I do this in a variety of places trying to find one that works. None do.
I expect setting ModalInPresentation = true should prevent the modal panel from being dismissed via swiping. It does not.
There is also a bug which I think the team knows of where swiping to dismiss corrupts the navigation stack. If I try to show the modal page again I get:
Warning: Attempt to present <Xamarin_Forms_Platform_iOS_ModalWrapper: 0x10782cc00> on <ModalPresentation_iOS_OTNavigationPageRenderer: 0x107128600> whose view is not in the window hierarchy!
This post talks about it: https://github.com/xamarin/Xamarin.Forms/issues/7364
Related
Above mentioned solution is not working for my project in iOS , (this,"false") can you please help me to sort out the issue . Screenshot attached for your reference. How to hide back button in navigation bar xamarin forms
If you want to set the title of this page, set a SetBackButton on the page you want to return to.
You can add the following code to the page's constructor to hide the back button:
NavigationPage.SetHasBackButton(this, false);
I have xamarin forms ios application,where I need to remove the back arrow in the navigation bar but the title should be displayed and when user clicks on on that back button title it should navigate to previous view.
I tried using `
NavigationPage.SetBackButtonTitle(this, "Cancel");
NavigationPage.SetHasBackButton(this, false);
But the back arrow is still displaying,is there any why to have only the text Cancel without <symbol?
I solved my issue by adding a custom renderer as follows
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
this.NavigationController.TopViewController.NavigationItem.LeftBarButtonItem =new UIBarButtonItem(“Cancel”, UIBarButtonItemStyle.Plain, (sender, args) => { });
}
In your AppDelegate.cs file, in the FinishedLaunching method add these lines:
UINavigationBar.Appearance.BackIndicatorImage = new UIImage();
UINavigationBar.Appearance.BackIndicatorTransitionMaskImage = new UIImage();
This will however, remove it for every page. If you want it for just one page I would suggest like EvZ already mentioned: use a modal page or find another way.
Another way is to set the above lines to null which will restore the normal arrow. But this would mean implementing a custom renderer, dependency service or similar.
Remove navigation-bar and use image/header on navigation place and write into image/Header into navigation title...
image onclick event into write back command
I am trying to add an image next to the hamburger menu in my app. I am using a master detail page and it renders fine in ios and android. I tried using setting the icons for the detail pages. but the icons never showed. How do I achive this. I am looking to add an image similar to the amazon app.
I checked out this app on my phone and it uses a lot of custom constructions that aren't supported by out of the box Xamarin Forms controls. Something like the back arrow next to the hamburger menu is not a standard thing (on iOS at least). Also looking at the actual menu that the hamburger button triggers it becomes clear that its not an out of the box hamburger menu. Theirs pops over the content instead of sliding it out of view as the built-in one does.
More than likely they implemented their own hamburger menu and navigation structure which gave them the freedom to add buttons next to it. If you want to achieve this with out of the box controls you will most likely need custom renderers for each platform to create a replica of this navigation structure.
What is built-in in Xamarin Forms is that you can set the page title to an image instead of text by using the NavigationPage.SetTitleIcon method, which could be used to achieve what you want:
public class MyPage : NavigationPage
{
public MyPage ()
{
var myContentPage = new MyContentPage (Color.White);
this.Push (myContentPage);
var s = "icon.png";
NavigationPage.SetTitleIcon (myContentPage, s);
}
}
Even then, this is limited in functionality. If you want to fiddle with the alignment of the image e.g. you would also need to resort to a custom renderer.
I am using Xamarin to build a simple app. In my app I use a series of classes that inherit from DialogViewController. In some cases, when the user clicks on an item, I use:
NavigationController.PushViewController( new DialogViewClass() , true );
This when the DialogViewClass() starts and sets up a new view, it might alter the state of the data that requires my current Dialog to be refreshed.
When the user finally backs out of the stack, and reshows my dialog, how do I capture "the event" that says my dialog is being redisplayed, so that I can update my view with current information?
Found my answer. In the class that inherits from DialogViewController, add this override:
override void ViewWillAppear( bool animated ) {
base.ViewWillAppear( animated );
// Show the page
}
In my case, simply rebuilding the interface based on the values in my constructor is good enough whether the page is being loaded for the first time, or is being reloaded after a POP action.
When showing the achievements dialog using GKAchievementViewController, this works as expected.
However, when showing the leaderboard dialog using GKLeaderboardViewController, I simply a grey screen and no Done button. Furthermore, it appears to be in the wrong orientation on an iPhone.
Here is the code:
this.leaderboardController.TimeScope = GKLeaderboardTimeScope.AllTime;
this.leaderboardController.Category = "myLeaderboardId";
this.leaderboardController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
this.leaderboardController.DidFinish += (senderLeaderboard, eLeaderboard) =>
{
this.leaderboardController.DismissViewController(true, null);
};
viewController.PresentViewController(this.leaderboardController, false, null);
I am using the same view controller that I use for showing the achievements dialog from Game Center.
I cannot dismiss the leaderboard dialog because it does not even have a 'Done' button.
Okay, the problem was that I was initializing the view controller in the constructor of my class. This was too early, instead I lazy-initialize (initialize only if\when needed). This fixed all the above mentioned problems.