Why won't Silverlight handle the conversion of my custom float property

你。 提交于 2020-01-02 04:40:10

问题


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 http://www.farseergames.com/storage/share/PropertyInBlend.Png

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

Failed to create a 'Windows.Foundation.Single' from the text '0.0'

alt text http://www.farseergames.com/storage/share/SilverlightError.Png

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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/2672076/why-wont-silverlight-handle-the-conversion-of-my-custom-float-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!