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. WCF and WF
  4. How to assign customer object to the dependency property in xaml?

How to assign customer object to the dependency property in xaml?

Scheduled Pinned Locked Moved WCF and WF
wpfsalestutorialquestion
2 Posts 2 Posters 0 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.
  • E Offline
    E Offline
    Eric Vonjacson
    wrote on last edited by
    #1

    Hi All, I have one class that has a dependency property that like this:

    public partial class BSTreeNode : UserControl
    {

    //....
    public static readonly DependencyProperty ParentNodeProperty = DependencyProperty.Register(
    "ParentNode", typeof(BSTreeNode), typeof(BSTreeNode),
    new FrameworkPropertyMetadata(null, null), null);

        public BSTreeNode ParentNode
        {
            \[DebuggerStepThrough\]
            get
            {
                return (BSTreeNode)this.GetValue(BSTreeNode.ParentNodeProperty);
            }
            \[DebuggerStepThrough\]
            set
            {
                this.SetValue(BSTreeNode.ParentNodeProperty, value);
            }
        }
    

    }

    The type of property "ParentNode" is same as this class. In the xaml file, I defined and used them like this:

      <local:BSTreeNode NodeContent="A" Canvas.Left="100" Canvas.Top="20" x:Name="A"> 
      <local:BSTreeNode NodeContent="B" Canvas.Left="20" Canvas.Top="200" x:Name="B" **ParentNode="A"**\></local:BSTreeNode>
    

    However, the application will throw out an exception. So how to set the dependency property in the xaml file like this? Is it possible? thanks, GuoYu Feng

    A 1 Reply Last reply
    0
    • E Eric Vonjacson

      Hi All, I have one class that has a dependency property that like this:

      public partial class BSTreeNode : UserControl
      {

      //....
      public static readonly DependencyProperty ParentNodeProperty = DependencyProperty.Register(
      "ParentNode", typeof(BSTreeNode), typeof(BSTreeNode),
      new FrameworkPropertyMetadata(null, null), null);

          public BSTreeNode ParentNode
          {
              \[DebuggerStepThrough\]
              get
              {
                  return (BSTreeNode)this.GetValue(BSTreeNode.ParentNodeProperty);
              }
              \[DebuggerStepThrough\]
              set
              {
                  this.SetValue(BSTreeNode.ParentNodeProperty, value);
              }
          }
      

      }

      The type of property "ParentNode" is same as this class. In the xaml file, I defined and used them like this:

        <local:BSTreeNode NodeContent="A" Canvas.Left="100" Canvas.Top="20" x:Name="A"> 
        <local:BSTreeNode NodeContent="B" Canvas.Left="20" Canvas.Top="200" x:Name="B" **ParentNode="A"**\></local:BSTreeNode>
      

      However, the application will throw out an exception. So how to set the dependency property in the xaml file like this? Is it possible? thanks, GuoYu Feng

      A Offline
      A Offline
      ABitSmart
      wrote on last edited by
      #2

      Try it this way,

      ParentNode="{Binding ElementName=A}"

      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