Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DependencyProperty problem with Double and Single

Silverligh 4, VS 2010.

Making a Custom Control. (Non just UserControl, but public class HandPart : Control, and a template in \themes)

Then I creating a new DependencyProperty with a helper snippet:

#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

As a result solution is compiling with out any errors and messages but it not starting up. When I creating DependencyProperty with, fore example, Int type insted Double or Single, it's working OK.

What is the problem, (feature?) with float? Why I can't create DP with a floats types?

like image 300
Alexandr Belan Avatar asked Feb 28 '23 21:02

Alexandr Belan


1 Answers

The 0 argument that you're passing to the PropertyMetadata constructor will be interpreted as an int rather than a double. Try passing 0.0 instead:

public static readonly DependencyProperty SomeDoubleProperty =
    DependencyProperty.Register("SomeDouble", typeof(Double),
        typeof(HandPart), new PropertyMetadata(0.0));
like image 99
LukeH Avatar answered Mar 07 '23 02:03

LukeH