OnPlatform Returns default value Always.

Hello all!

I have the following resource dictionary:

    <ResourceDictionary>
            <!-- DEFINE ANY CONSTANTS -->
            <x:Double   x:Key="BorderWidth"> 3 </x:Double>

            <Color x:Key="HighlightColor" >
                <OnPlatform x:TypeArguments="Color"   iOS="#CCCCCC"   Android="#CCCCCC"   WinPhone="#CCCCCC"/>
            </Color>

            <Color x:Key="TextColor" >
                <OnPlatform x:TypeArguments="Color"   iOS="#CCCCCC"   Android="#CCCCCC"   WinPhone="#CCCCCC"/>
            </Color>

            <Color x:Key="BorderColor" >
                <OnPlatform x:TypeArguments="Color"   iOS="#292F33"   Android="#292F33"   WinPhone="#888888"/>
            </Color>

            <Color x:Key="FocusColor"  >
                <OnPlatform x:TypeArguments="Color"   iOS="#7E827A"   Android="#7E827A"   WinPhone="#BBBBBB"/>
            </Color>

            <Color x:Key="BackgroundColor">
                <OnPlatform x:TypeArguments="Color"   iOS="#111111"   Android="#111111"   WinPhone="#00FFFF"/>
            </Color>

        </ResourceDictionary>

And when I access these resources from code using:

        static private Object GetResource(string name)
        {
            return Application.Current.Resources[name];
        }

        static public Color _TextColor;
        static public Color TextColor
        {
            get
            {
                _TextColor = (Color)GetResource("TextColor");
                return _TextColor;
            }
        }

Question 1: The value of text color on UWP is always 0,0,0,0. Does anyone have any idea why this is?
Question 2: Why is there no OnPlatform for UWP.

Answers

  • ClintStLaurentClintStLaurent ✭✭✭✭✭ USUniversity ✭✭✭✭✭
    edited August 2017

    Just as a test, try using a pre-defined color by name (Make sure it is a valid Windows color name) instead of hex. Maybe there is an issue with using hex.

  • DavidLedgerDavidLedger ✭✭ AUMember ✭✭

    @ClintStLaurent said:
    Just as a test, try using a pre-defined color by name (Make sure it is a valid Windows color name) instead of hex. Maybe there is an issue with using hex.

    Am not able to do that, I cannot manually do that for hundreds of things each change even if it does work.

  • ClintStLaurentClintStLaurent ✭✭✭✭✭ USUniversity ✭✭✭✭✭

    Nobody said it would solve your issue or that you should do it for hundreds of colors. Just suggested a 10 minute test with a hand full of definitions where you could confirm the bug.

    I would suggest you stop and thing about this for a second... you want others to have the answers for you - but you can't take 10 minutes to run a test to confirm that there actually is a bug where it works one way but not another. That's a lot of 'take' with no 'give'. Is that who you want to be known as? We've all worked with 'that guy' and they don't last long in this industry.

  • DavidLedgerDavidLedger ✭✭ AUMember ✭✭
    edited November 2017

    @ClintStLaurent said:
    Nobody said it would solve your issue or that you should do it for hundreds of colors. Just suggested a 10 minute test with a hand full of definitions where you could confirm the bug.

    I would suggest you stop and thing about this for a second... you want others to have the answers for you - but you can't take 10 minutes to run a test to confirm that there actually is a bug where it works one way but not another. That's a lot of 'take' with no 'give'. Is that who you want to be known as? We've all worked with 'that guy' and they don't last long in this industry.

    Didn't see your reply for months, rushed a response when I did.

    Please don't immediately judge me, there is a follow-up, I happen to be in what is likely a different time zone, and was tired. I tried but I got stuck an error message that only appeared in new project "Can not set the content of Color as it doesn't have a ContentPropertyAttribute'", didn't have the time to work on it then. I recognise your trying to help, thanks but communication is not always perfect, complete or accurate.

    As far as I can tell it use to fail silently, but now fails in runtime took a while to find what was going on
    https://bugzilla.xamarin.com/show_bug.cgi?id=55921

    This works, no idea why my old syntax didn't.
    <OnPlatform x:TypeArguments="Color" Android="Red" iOS="Blue" WinPhone="#00FFAA" x:Key="Fred" />
    <OnPlatform x:TypeArguments="Color" Android="Red" iOS="Blue" WinPhone="Red" x:Key="Fred" />

Sign In or Register to comment.