silverlight: How to set attached properties Progra

2019-03-14 20:10发布

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?

3条回答
迷人小祖宗
2楼-- · 2019-03-14 20:44

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); 
查看更多
唯我独甜
3楼-- · 2019-03-14 20:45

To set the value:

textBlock.SetValue(Grid.RowProperty, 3);

To reset the value:

textBlock.SetValue(Grid.RowProperty, null);
查看更多
霸刀☆藐视天下
4楼-- · 2019-03-14 20:47

Actually to clear a value you should use this:

textBlock.ClearValue(Grid.RowProperty);
查看更多
登录 后发表回答