Wpf 通过编程更改控件的位置
我有这样一个xaml代码Wpf 通过编程更改控件的位置,wpf,Wpf,我有这样一个xaml代码 <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="100"/> <ColumnDefinition Width="100"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Hei
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<Label Content="Test" Grid.Column="1" Grid.Row="1" Height="100" Width="100" FontSize="20" Name="label"/>
<Button Content="Change" Grid.Column="0" Grid.Row="0" Click="Button_Click" />
</Grid>
如何在单击按钮时更改标签的位置。即,更改标签的行和列
感谢使用网格控件ColumnProperty和RowProperty,如下所示:
label.SetValue(Grid.ColumnProperty, 0);
label.SetValue(Grid.RowProperty,0);
使用网格控件ColumnProperty和RowProperty,如下所示:
label.SetValue(Grid.ColumnProperty, 0);
label.SetValue(Grid.RowProperty,0);
除了阿南德的回答,你也可以这样做:
Grid.SetColumn(label, 0);
Grid.SetRow(label, 0);
除了阿南德的回答,你也可以这样做:
Grid.SetColumn(label, 0);
Grid.SetRow(label, 0);