Error: Unable to convert "White" to float4 if passed as Observable value

This works…

    <Text Color="White">My Text </Text>

If I make it the color property a variable

    <Text Color="{targetColor}">My Text </Text>

Setting the Color via String throws the error:

var targetColor = Observable("White")

= ERROR

Setting the Color via #hex value works

var targetColor = Observable("#FFF")

= OK

What am I missing here?

PS I tried setting a global pallete value

        <Panel ux:Class="ColorPalette">
            <float4 ux:Global="White" ux:Value="#FFF" />
        </Panel>

and that still doesn’t work…

It’s a bit unclear whether setting the observable via hex works for you or not. You say it works, but then also ERROR? Ref:

Setting the Color via #hex value works var targetColor = Observable(“#FFF”) = ERROR

Anyway, I would expect that setting the hex values from javascript works, whereas trying to use “White” in javascript won’t work because it’s not defined anywhere in the JavaScript context.

Remi Pedersen wrote:

It’s a bit unclear whether setting the observable via hex works for you or not. You say it works, but then also ERROR? Ref:

Setting the Color via #hex value works var targetColor = Observable(“#FFF”) = ERROR

Anyway, I would expect that setting the hex values from javascript works, whereas trying to use “White” in javascript won’t work because it’s not defined anywhere in the JavaScript context.

Hi Remi. First of all, my apologies for the confusion. I actually corrected my post.

So to confirm, setting the Color via #hex value works

 var targetColor = Observable("#FFF");// This Works 

Now, I understand what you mean about JS “White” not being defined anywhere in the JS Context, but I don’t think this is the case. I am merely passing the string “White” into the Color declaration.

var targetColor = Observable("White");// White=String not Variable

so this…

<Text Color="{targetColor}">My Text </Text>

…should be equal to this…

<Text Color="White">My Text </Text>

… is it not?

Not really. :slight_smile: Without being an expert I’d say that it’s very likely that setting a property to a constant struct (which is what White is a helper-alias for here) behaves differently than binding it to an observable in JavaScript.

Either way, if you want to be able to use convenience-aliases (“text names”) for colors in javascript then you should define them there. :slight_smile: (After all, defining them on your own also means you’ll know which RGB colors they actuall represent).

Remi Pedersen wrote:

Not really. :slight_smile: Without being an expert I’d say that it’s very likely that setting a property to a constant struct (which is what White is a helper-alias for here) behaves differently than binding it to an observable in JavaScript.

Either way, if you want to be able to use convenience-aliases (“text names”) for colors in javascript then you should define them there. :slight_smile: (After all, defining them on your own also means you’ll know which RGB colors they actuall represent).

Ohh…OK. I guess I’m thinking of this in a very plain Variable=Value representation which I guess is wrong in the get go.

Anyway, it’s no biggie I don’t mind doing RGB, I was just trying to understand the situation.

Thanks!