Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Changing current ContentPage colours at runtime.

$
0
0

I have a navigation page that pushes other pages into view. A typical navigation pattern and that works well.

I have a static class which contains the colors used by the system. The controls in my XAML pages used those colours as follows:

Background="{x:Static local:GlobalHelper.MyColor}"

That part is working fine too.

On the root page I have some 'Set Theme' buttons. When pressed these change the color variables, e..g Button1 might change background colour to Blue, while Button2 might change background colour to Red.. When I push one of the sub pages into view, the colours are these sub pages are used correctly. So the background will be either Red or Blue depending on the 'Set Theme' button that had been pressed.

Now comes the problem part. I want that root page to change colours immediately the 'Set Theme' button is pressed. I have tried to do a custom renderer which listens for a property to be changed and it does an Invalidate() in the Android version. The call to Invalidate() is being made, exactly when I expect, so that part is working. What is NOT working is that the colours don't change. Is that because the Background property being set via:

Background="{x:Static local:GlobalHelper.MyColor}"

and this is only called on the constructor of the page? And not on an Invalidate()? Am I wasting my time trying to get this to work in this way?

The only alternative I can think of is to recreate the page and set the root page of the app to the newly created page. I haven't tried it yet but my concern with that approach is that there would be a flicker as the page changed.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>