0
這是我的XAML:爲什麼2個按鈕仍然重疊
<Grid>
<Button x:Name="top1" Content="top" Width="200" Height="50" VerticalAlignment="Top" HorizontalAlignment="Center"/>
<Button x:Name="top2" Content="top" Width="100" Height="25" VerticalAlignment="Top" HorizontalAlignment="Center"/>
<Button x:Name="left" Content="left" Width="200" Height="50" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,0,0,0" Click="Button_Click"/>
</Grid>
當我點擊左鍵,我想TOP2按鈕,向左走,以避免與TOP1按鈕重疊。這裏是我的背景代碼:
private void Button_Click(object sender, RoutedEventArgs e)
{
var offset = this.top1.ActualWidth + this.top2.ActualWidth/2;
this.top2.Margin = new Thickness(0, 0, offset, 0);
}
爲什麼會發生這種情況?以及如何解決?
因爲'Grid'元素可以重疊,並且您的按鈕在給定空間內水平居中 – dkozl