Getting and Setting Attached Property Values in Code

Although it's a somewhat different topic to data binding, getting and setting the value of an attached property on a control is similar to getting and setting bindings. Use the GetValue method of a control, passing it the dependency property corresponding to the attached property, to get the given attached property's value for that control. For example, use the following code to get which grid row a text box control named NameTextBox is in (hence, get the value of the Grid.Row attached property on the text box):

int row = (int)NameTextBox.GetValue(Grid.RowProperty);

You can then assign a different value to that attached property if you wish, using the SetValue method of the control, and passing ...

Get Pro Business Applications with Silverlight 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.