【问题标题】:DependencyProperty problem with Double and SingleDouble 和 Single 的 DependencyProperty 问题
【发布时间】:2009-12-22 11:44:22
【问题描述】:

Silverlight 4,VS 2010。

制作自定义控件。 (不仅仅是 UserControl,还有公共类 HandPart : Control 和 \themes 中的模板)

然后我使用助手 sn-p 创建一个新的 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

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

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

【问题讨论】:

    标签: .net silverlight silverlight-4.0 dependency-properties


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 2015-05-12
      相关资源
      最近更新 更多