Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. float Dependency Property Exception

float Dependency Property Exception

Scheduled Pinned Locked Moved WPF
wpfhelpcsharphtmlcss
3 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RNEELY
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • R RNEELY

      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

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      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.

      My blog | My articles

      R 1 Reply Last reply
      0
      • P Pete OHanlon

        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.

        My blog | My articles

        R Offline
        R Offline
        RNEELY
        wrote on last edited by
        #3

        Yes that worked. Thanks. :)

        Sincerely, -Ron

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups