2009-04-21 23 views
1

我有這樣改變控件的位置編程

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

一個XAML代碼如何更改標籤的位置,當我點擊按鈕。即更改標籤的行和列。

感謝

回答

3

除了阿南德的答案,你也可以那樣做:

Grid.SetColumn(label, 0); 
Grid.SetRow(label, 0); 
1

使用網格控件COLUMNPROPERTY和RowProperty這樣的:

label.SetValue(Grid.ColumnProperty, 0); 
label.SetValue(Grid.RowProperty,0);