.NET Framework Developer Center > .NET Development Forums > Windows Presentation Foundation (WPF) > How do I bind to properties from a UserControl.FixedTemplate?
Ask a questionAsk a question
 

AnswerHow do I bind to properties from a UserControl.FixedTemplate?

  • Wednesday, November 23, 2005 1:25 PMjedediah3 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    There is a DP called Value in my UserControl derived class and I want to bind to it from one of the elements in UserControl.FixedTemplate. I have tried all of the following:

    {Binding Value}
    {TemplateBinding Value}
    {Binding RelativeSource=/TemplatedParent,Path=Value}

    In every case, I get an error message like this:
    "BindingExpression path error: Cannot find property 'Value' on object 'null'."


Answers

  • Wednesday, November 23, 2005 5:04 PMMichaelLattaModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    The "on object null" part is the issue.  You are not setting your control as the data context for the binding.  I am familiar with ControlTemplate for custom controls, not FixedTemplate, and have not used UserControls yet.  But, on several of my custom controls I have had to use /TemplatedParent/TemplatedParent to get to the proper object.  I would play with things like that until you are able to get the message to have an object other than null.  I am still getting my app up to speed for the Nov bits, so I can not for sure say there are no problems in this area.

All Replies

  • Wednesday, November 23, 2005 5:04 PMMichaelLattaModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    The "on object null" part is the issue.  You are not setting your control as the data context for the binding.  I am familiar with ControlTemplate for custom controls, not FixedTemplate, and have not used UserControls yet.  But, on several of my custom controls I have had to use /TemplatedParent/TemplatedParent to get to the proper object.  I would play with things like that until you are able to get the message to have an object other than null.  I am still getting my app up to speed for the Nov bits, so I can not for sure say there are no problems in this area.