sthewissen / Xamarin.Forms.DebugRainbows

The package you didn't even know you needed!
MIT License
415 stars 33 forks source link

Doesn't work in toolbar Clicked event #27

Closed IeuanWalker closed 4 years ago

IeuanWalker commented 4 years ago

Trying to set some toolbar items to help make it easier to debug. The below code has been added to a base page.

In the page constructor I've added this -

#if DEBUG
            ToolbarItem rainbowToggle = new ToolbarItem
            {
                Text = "Rainbow",
                Order = ToolbarItemOrder.Secondary,
                Priority = 1
            };
            rainbowToggle.Clicked += RainbowToggleClicked;
            this.ToolbarItems.Add(rainbowToggle);
#endif

Then the clicked event is this (will add a property to toggle the option once it works) -

#if DEBUG

        void RainbowToggleClicked(object sender, EventArgs e)
        {
            DebugRainbow.SetShowColors(this, true);
        }
#endif

The DebugRainbow.SetShowColors() line is hit without error but none of the colours changes. Adding DebugRainbow.SetShowColors(this, true); to the constructor works fine.

Same issue with SetShowGrid()

sthewissen commented 4 years ago

Correct. What happens is that DebugRainbows hooks into the page events just before it's being displayed to go through all the elements and change the color depending on those ShowGrid / ShowColors booleans.

What you're essentially doing on the button click is setting the boolean to true that it needs to change elements, but the necessary page reload that actually does this is not happening. This is why you don't see the changes. It's very much meant to work in unison with a HotReload kind of component instead of being a runtime changeable thing.

IeuanWalker commented 4 years ago

@sthewissen thanks, makes sense :)