Accessing Controls in a Template to Databind Properties
Posted on: Wed Jun 18 16:12:49 -0700 2008. Updated on: Sat Jun 21 00:23:22 -0700 2008.
Category: Silverlight
Category: Silverlight
So, lets say that you created a silverlight button control and you are overriding the default template with your own defined template. Now, let's say you need to databind, say, the TextBlock text property on an event, but you cannot acces the TextBlock directly because it is within a template. Solution: Simply set the TextBlock Text property to:
{Binding ObjectPropertyName}
and then in the code behind in your event that will bind the data, go:
Button.DataContext = ObjectWithDefinedProperties;