-3

我在 windows phone 项目中遇到了一个可怕的问题。我正在设计一个页面中心有两个按钮的页面,这里是 xaml 代码:

<StackPanel x:Name="Mainpg00" Visibility="Visible">
            <Button Width="200" HorizontalAlignment="Left" Height="200" Click="Button1_Click" VerticalAlignment="Center">
            <Button.Content>
                <TextBlock TextWrapping="Wrap" Text="Generate Registration OTP"/>
            </Button.Content>
        </Button>

        <Button Width="200" HorizontalAlignment="Right" Height="200" Click="Button2_Click" VerticalAlignment="Center">
            <Button.Content>
                <TextBlock TextWrapping="Wrap" Text="Proceed with OTP"/>
            </Button.Content>
        </Button>
        </StackPanel>

我面临的问题是我无法在页面中心设置按钮。请帮忙。

4

1 回答 1

0

如果居中,您的意思是:

在此处输入图像描述

然后,将 StackPanel 的 Orientation 属性设置为 Horizo​​ntal。这里有代码:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <StackPanel x:Name="Mainpg00" Visibility="Visible" Orientation="Horizontal" HorizontalAlignment="Center">
        <Button Width="200" HorizontalAlignment="Left" Height="200" Click="Button1_Click" VerticalAlignment="Center">
            <Button.Content>
                <TextBlock TextWrapping="Wrap" Text="Generate Registration OTP"/>
            </Button.Content>
        </Button>

        <Button Width="200" HorizontalAlignment="Right" Height="200" Click="Button2_Click" VerticalAlignment="Center">
            <Button.Content>
                <TextBlock TextWrapping="Wrap" Text="Proceed with OTP"/>
            </Button.Content>
        </Button>
    </StackPanel>
    </Grid>

否则,如果你想要的是这样的:

在此处输入图像描述

然后使用对齐和按钮大小:

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <StackPanel x:Name="Mainpg00" Visibility="Visible" VerticalAlignment="Center">
        <Button Click="Button1_Click" VerticalAlignment="Center">
            <Button.Content>
                <TextBlock TextWrapping="Wrap" Text="Generate Registration OTP"/>
            </Button.Content>
        </Button>

        <Button Click="Button2_Click" VerticalAlignment="Center">
            <Button.Content>
                <TextBlock TextWrapping="Wrap" Text="Proceed with OTP"/>
            </Button.Content>
        </Button>
    </StackPanel>
    </Grid>
于 2013-04-23T12:52:08.013 回答