How to assign customer object to the dependency property in xaml?
-
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
-
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