How to add wpf control to particular grid row and cell during runtime?

前端 未结 2 1632
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 05:15

I have the following grid in my WPF \"Window\" (yes the class Window);


            
                 


        
2条回答
  •  悲哀的现实
    2020-12-15 05:49

    The Grid.Row and Grid.Column properties are Attached Properties, and as such are not set like normal .net properties. The right way to set them from code is:

    Grid.SetRow(someLabel, 0);
    Grid.SetColumn(someLabel, 0);
    

    You should be able to do this before or after adding them to the Grid object's Children collection, but setting them before adding the control should prevent any possible flickering.

提交回复
热议问题