Double和Single的DependencyProperty问题

FFi*_*ire 3 .net silverlight dependency-properties silverlight-4.0

Silverligh 4,VS 2010.

进行自定义控制.(不仅仅是UserControl,而是公共类HandPart:Control,以及\ themes中的模板)

然后我用一个帮助器片段创建一个新的DependencyProperty:

#region SomeDouble (DependencyProperty)

/// <summary>
/// A description of the property.
/// </summary>
public Double SomeDouble
{
    get { return (Double)GetValue(SomeDoubleProperty); }
    set { SetValue(SomeDoubleProperty, value); }
}
public static readonly DependencyProperty SomeDoubleProperty =
    DependencyProperty.Register("SomeDouble", typeof(Double), typeof(HandPart),
      new PropertyMetadata(0));

#endregion
Run Code Online (Sandbox Code Playgroud)

因此,解决方案是编译没有任何错误和消息,但它没有启动.当我创建DependencyProperty时,例如,Int类型insted Double或Single,它工作正常.

浮动有什么问题,(功能?)?为什么我不能用浮点类型创建DP?

Luk*_*keH 6

0您传递给PropertyMetadata构造函数的参数将被解释为int而不是double.尝试传递0.0:

public static readonly DependencyProperty SomeDoubleProperty =
    DependencyProperty.Register("SomeDouble", typeof(Double),
        typeof(HandPart), new PropertyMetadata(0.0));
Run Code Online (Sandbox Code Playgroud)