Does WinPhone treat Color.Default differently in some circumstances? Probably bug.

JohnHardmanJohnHardman GBUniversity mod

Whilst implementing a control, based on a Label, that when tapped results in navigation to a new page, I hit a funny with the use of Color.Default on WinPhone. So that the user had instant feedback that the tap had been recognised, I thought I would flash the background, first to Color.Accent and then back to Color.Default, before navigating to the new page. The code for this is below.

On Android, this seems to work fine (although the timing is not great), but on WinPhone, the background color is left as Color.Accent. Initially, I thought this was probably a timing or sequencing problem, but then I changed Color.Default to Color.Black, at which point it worked. Switch it back to Color.Default and it stops working. Does anybody know of any intentional interaction between Color.Accent and Color.Default?

public class ExperimentTappableLabel : Label
{
    public ExperimentTappableLabel() : base()
    {
        TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer();
        tapGestureRecognizer.Tapped += (s, e) =>
        {
            if (Command != null)
            {
                int stateCounter = 0;
                BackgroundColor = Color.Accent;
                Device.StartTimer(
                    new TimeSpan(0, 0, 0, 0, 10),
                    () =>
                    {
                        switch (stateCounter++)
                        {
                            case 5:
                                BackgroundColor = Color.Default;
                                return true;
                            case 6:
                                Command.Execute(CommandParameter);
                                return false;

                        }
                        return true;
                    });
            }
        };

        GestureRecognizers.Add(tapGestureRecognizer);
    }

    public ICommand Command { get; set; }
    public object CommandParameter { get; set; }
}

Answers

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @JohnHardman:
    Some time ago, I had strange problems with a label (unfortunately I don't remember the platform).
    In my app, I have defined global color-variables (E.G. color.standard, color.red, etc.) and set the colors at startup.
    In the app, I then set the Label.Textcolor with this variables.
    For color.standard, I had not assigned a color-value but Color.Default, what have cost me hours to find out the problem. At the end, I have debugged the whole code step by step with debugger (including what Color.Default contains).
    The problem was, that for one platform (don't remember which), the Color.Default has give back some s....
    So... I have changed my app then to set also the color.standard-variable myself for each platform.

    Hope this helps...

  • JohnHardmanJohnHardman GBUniversity mod
    edited May 2015

    @FredyWenger - Thanks Fredy. Yes, I am also having a central store in my code from which I get the colors to use in different context. Similarly, font sizes, font families etc. are all obtained from one central store. It makes life much easier when trying to make things look right on 3 types of phone, 3 types of tablet, and eventually Windows Store too, if UI-specific values are not scattered throughout the application.

    I am also considering creating a Dependency Service that provides each of the workarounds that I have had to introduce for XF bugs. That way, I will be able to keep track of my workarounds, rather than forgetting where they are and what they are for...

    BTW - I read your XF starter guide the other day - should be very useful to people starting with XF. I certainly marked a few pages where I found things I should be doing. Many thanks.

Sign In or Register to comment.