Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 通过编程更改控件的位置_Wpf - Fatal编程技术网

Wpf 通过编程更改控件的位置

Wpf 通过编程更改控件的位置,wpf,Wpf,我有这样一个xaml代码 <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="100"/> <ColumnDefinition Width="100"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Hei

我有这样一个xaml代码

<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);