如何从 wpf 中的代码后面更改控件的 Grid.Row 和 Grid.Column [英] How to change the Grid.Row and Grid.Column of the control from code behind in wpf
本文介绍了如何从 wpf 中的代码后面更改控件的 Grid.Row 和 Grid.Column的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将控件放在 DataGrid
中,如下所示:
I have the control placed in DataGrid
like this:
<Label Name="lblDescription" HorizontalAlignment="Left" Margin="0,5,0,0" Grid.Row="2" Grid.Column="2" />
<TextBox Name="txtDescription" HorizontalAlignment="Left" Width="200" Margin="0,5,0,0" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" AcceptsReturn="True" Grid.RowSpan="2" Grid.Row="2" Grid.Column="3" />
如何在后面的代码中更改控件的Grid.Row
和Grid.Column
?
How can I change the Grid.Row
and Grid.Column
of the control in code behind?
推荐答案
还有一个静态方法可以做到这一点(类似于在代码中使用属性来设置非附加属性,而不是在那里使用 DP).
There is also a static method to do this (analogous to using the property in code to set a non-attached property rather than using the DP there).
Grid.SetRow(txtDescription, 1);
您可能会发现这更具可读性.
You may find this more readable.
这篇关于如何从 wpf 中的代码后面更改控件的 Grid.Row 和 Grid.Column的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文