float Dependency Property Exception
-
Please help me resolve the exception that get's thrown below when I try to run an app with one simple float dependency property. It is a default WPF window app with the following added to Window 1 to create a float dependency property:
public partial class Window1 : Window { public Window1() { InitializeComponent(); } public static readonly DependencyProperty DependFloatProperty = DependencyProperty.Register("DependFloat", typeof(float), typeof(Window1), new UIPropertyMetadata(0.0)); public float DependFloat { get { return (float)GetValue(DependFloatProperty); } set { SetValue(DependFloatProperty, value); } } }
Following is the xaml:<Window x:Class="Dependent.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Grid> </Grid> </Window>
When I run the app I get the following exception: System.Windows.Markup.XamlParseException was unhandled Message="Cannot create instance of 'Window1' defined in assembly 'Dependent, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Window1.xaml' Line 1 Position 9." Source="PresentationFramework" LineNumber=1 LinePosition=9 ...Sincerely, -Ron
-
Please help me resolve the exception that get's thrown below when I try to run an app with one simple float dependency property. It is a default WPF window app with the following added to Window 1 to create a float dependency property:
public partial class Window1 : Window { public Window1() { InitializeComponent(); } public static readonly DependencyProperty DependFloatProperty = DependencyProperty.Register("DependFloat", typeof(float), typeof(Window1), new UIPropertyMetadata(0.0)); public float DependFloat { get { return (float)GetValue(DependFloatProperty); } set { SetValue(DependFloatProperty, value); } } }
Following is the xaml:<Window x:Class="Dependent.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Grid> </Grid> </Window>
When I run the app I get the following exception: System.Windows.Markup.XamlParseException was unhandled Message="Cannot create instance of 'Window1' defined in assembly 'Dependent, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Window1.xaml' Line 1 Position 9." Source="PresentationFramework" LineNumber=1 LinePosition=9 ...Sincerely, -Ron
Your dependency property is declared incorrectly. Basically, it's not seeing the 0.0 as a float. Try replacing it with
public static readonly DependencyProperty DependFloatProperty =
DependencyProperty.Register("DependFloat",
typeof(float),
typeof(Window1),
new UIPropertyMetadata((float)0));Deja View - the feeling that you've seen this post before.
-
Your dependency property is declared incorrectly. Basically, it's not seeing the 0.0 as a float. Try replacing it with
public static readonly DependencyProperty DependFloatProperty =
DependencyProperty.Register("DependFloat",
typeof(float),
typeof(Window1),
new UIPropertyMetadata((float)0));Deja View - the feeling that you've seen this post before.