Closed ericbrunner closed 3 years ago
I'm not sure if it's possible, to be honest. The coloring is applied on page creation, so unless a new layout pass is performed the colors will stay. When it comes to Hot Reload (which this was kind of designed for) that works like a charm. When changing the boolean at runtime the pages that are already created will probably remain colored. Do new pages you spawn from that point onwards still get the color as well?
The app is a lecacy app which started back in 2014 as fully code-based UI (no XAML). There is only one ContentPage
. In that ContentPage
there is a Grid
where various ContentView
s are set at runtime. So to catch up all ContentView's ,too I added them as Style Setter like:
void EnableDebugRainbows(bool shouldUseDebugRainbows)
{
Resources.Add(new Style(typeof(ContentPage))
{
ApplyToDerivedTypes = true,
Setters = {
new Setter
{
Property = Xamarin.Forms.DebugRainbows.DebugRainbow.ShowColorsProperty,
Value = shouldUseDebugRainbows
}
}
});
Resources.Add(new Style(typeof(ContentView))
{
ApplyToDerivedTypes = true,
Setters = {
new Setter
{
Property = Xamarin.Forms.DebugRainbows.DebugRainbow.ShowColorsProperty,
Value = shouldUseDebugRainbows
}
}
});
}
EnableDebugRainbows(true);
Well the blue frame is the ContentView
's Area in my Grid
but the Content is not shown :-(
Is there any way to enable or disable DebugRainbows for all ContentPages and ContentViews at runtime. I tried to use that approach with MergedDictionaries like in that sample:
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/theming/theming
but it doesn't work- I created a Debug.xaml / Debug.xaml.cs and a NoDebug.xaml & NoDebug.xaml.cs like the Dark and Light theme in the sample. Then I used similar code to switch the Debug and NoDebug ResourceDictionary. But no effect. Ah to mention. In Debug.xaml I set Value to true, in NoDebug.xaml to false like
Debug
NoDebug
Thanks in advance if you have a running sample or a hint if it's possible to do the switch at runtime.