Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

silverlight: How to set attached properties Programmatically

Suppose I have a grid with some row definitions, and a child control in that grid. How would I go about setting the Grid.Row property of the child control programatically?

like image 893
Jeremy Avatar asked Jan 08 '09 19:01

Jeremy


3 Answers

To set the value:

textBlock.SetValue(Grid.RowProperty, 3);

To reset the value:

textBlock.SetValue(Grid.RowProperty, null);
like image 154
Michael S. Scherotter Avatar answered Nov 16 '22 08:11

Michael S. Scherotter


Actually to clear a value you should use this:

textBlock.ClearValue(Grid.RowProperty);
like image 34
Maurice Avatar answered Nov 16 '22 09:11

Maurice


I'm not 100% sure this is in SilverLight, but in WPF you call a static method (called SetX, where X is the property) on the type the attached property is defined on and pass it in which control to set the value on, and the value:

Grid.SetRow(MyControl, myRowNumber); 
like image 4
Steven Robbins Avatar answered Nov 16 '22 09:11

Steven Robbins