silverlight: How to set attached properties Programmatically

后端 未结 3 1926
小鲜肉
小鲜肉 2021-02-05 05:58

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条回答
  • 2021-02-05 06:18

    Actually to clear a value you should use this:

    textBlock.ClearValue(Grid.RowProperty);
    
    0 讨论(0)
  • 2021-02-05 06:22

    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); 
    
    0 讨论(0)
  • 2021-02-05 06:36

    To set the value:

    textBlock.SetValue(Grid.RowProperty, 3);
    

    To reset the value:

    textBlock.SetValue(Grid.RowProperty, null);
    
    0 讨论(0)
提交回复
热议问题