views:

97

answers:

2

In a Silverlight 4 project I have a class that extends Canvas:

public class AppendageCanvas : Canvas
{        
    public float Friction { get; set; }
    public float Restitution { get; set; }
    public float Density { get; set; }
}

I use this canvas in Blend by dragging it onto another control and setting the custom properties:

alt text

When I run the app, I get the following error when InitializeComponent is called on the control containing my custom canvas: alt text

I'm not sure why Silverlight isn't able to convert this property from it's string representation in Xaml, to the float that it is.

Anyone have any ideas?

A: 

Got this from twitter friend Cameron Albert:

That is odd, I wonder if it would fail if that was a double?

Switched to doubles and no more error. Still curious that floats don't work.

Jeff Weber
First question, if you add your own type converter or value converter, can you store the value? There may not be a single/float converter by default.
Jeff Wilcox
Second, internally in Silverlight for performance reasons, many doubles have single precision, and as a result this may an artifact of that.
Jeff Wilcox
+2  A: 

The Native Text Syntaxes sub-topic lists the types that Xaml natively knows how to convert. Fundementally the primitive types supported are double, int, bool and string.

AnthonyWJones