Xamarin Forms modal taking up full screen

Hi, this may take me a while to type, I have checked the forums and this is what I have tried. Basically I am trying to load a modal and not make it full screen.

My first approach was to load the modal using

Navigation.PushModalAsync(_workInProgressModal, true);

And to close

Navigation.PopModalAsync(true);

The _workInProgressModal is a new version of my page...

_workInProgressModal = new WorkInProgressPage();

Within the xaml I set the background of its ContentPage to be transparent, and then StackLayout to be centred, not to fill screen


This works perfectly, the modal appears in centre and can see the parent page that calls the modal. HOWEVER....I have a global style set for my navigation bar, on my base page I set the global styles

        var navigationBarStyle = new Style(typeof(NavigationPage))
        {
            Setters =
            {
                new Setter() { Property = NavigationPage.BarBackgroundColorProperty, Value = Color.FromHex("29a329") },
                new Setter() { Property = NavigationPage.BarTextColorProperty, Value = Color.FromHex("660066") }
            }
        };

        appResourceDictionary.Add(navigationBarStyle);

The appResourceDictionary is Application.Current.Resources

This works fine when navigating between pages. But when the popup closes, the style for the navigation bar resets to default style. It actually occurs when the modal loads, as the navigation bar disappears when the modal loads, and I can see as it disappears that the default colour has returned. On close of modal the parent page has lost the app background colour in navigation bar and so looks odd. The OnAppearing code does not get triggered so not sure how to resolve this, and even if it was triggered, I'm not sure how to get page to pick up the global style, its like it has forgotten it! Not sure if this is a bug or not.

So my solution for now is to change the _workInProgressModal. Instead of it being

_workInProgressModal = new WorkInProgressPage();

I have changed it to

_workInProgressModal = new NavigationPage(new WorkInProgressModalPage());

Interestingly, when doing this, the navigation bar doesn't disappear when the modal is opened so I hide it in the code. But when the modal closes, the style of parent page is not lost. The problem with this is that the Transparent style of the content page is not recognised. I have tried setting it in the xaml and code behind, both with hex values and RGBA but whenever I set things to Transparent then the background is black. Even making it slightly opaque doesn't work, just goes grey.

So I am at a frustrating point, I have to go for later solution for now. I have seen that there is a Popup module on github that people refer to but I cant get that to compile at the moment, so any other advise will be great. Not sure if above descriptions are bugs in xamarin, or I'm doing something odd. If they are bugs, is there a place to post this to get them verified as bugs?

Many thanks

This is currently on android by the way

Sign In or Register to comment.