简体   繁体   English

XAML UWP自适应按钮

[英]XAML UWP Adaptive Buttons

I am trying to implement two side-by-side responsive buttons and I want them to behave like on the image below. 我正在尝试实现两个并排的响应按钮,我希望它们的行为如下图所示。

抓屏

This is my XAML: 这是我的XAML:

<RelativePanel x:Name="contentPanel">
       <Button x:Name="submitButton" Content="Submit"
                Margin="0,40,0,0"
                MinWidth="250"
                RelativePanel.AlignLeftWithPanel="True"/>

        <Button x:Name="annulerButton" Content="Cancel"
                Margin="5,40,0,0"
                MinWidth="250"
                RelativePanel.RightOf="submitButton"
                RelativePanel.AlignRightWithPanel="True"/>
<RelativePanel/>

Please, any help? 请帮忙吗?

Use Grid with ColumnDefinition something like below. 使用带有ColumnDefinition Grid ,如下所示。

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Button x:Name="submitButton" Content="Submit" Margin="5" Grid.Column="0" HorizontalAlignment="Stretch" />
    <Button x:Name="annuleButton" Content="Cancel" Margin="5" Grid.Column="1" HorizontalAlignment="Stretch"/>
</Grid>

and end output will be 并且结束输出将是

在此输入图像描述

You can use the open-source implementation of the UniformGrid for UWP instead of the relative panel. 您可以使用UWP的UniformGrid的开源实现而不是相对面板。

Alternatively, you can try to put your buttons into the standard Grid control, though it may misbehave if resized to a rather small size. 或者,您可以尝试将按钮放入标准网格控件中,但如果将其调整为相当小的尺寸,则可能会出现错误。 But as the buttons' minimal width is set to the same value in your case, you will not face this issue. 但是,由于按钮的最小宽度在您的情况下设置为相同的值,您将不会遇到此问题。

<Grid x:Name="contentPanel">
   <Grid.ColumnDefinitions>
       <ColumnDefinition Width="*" />
       <ColumnDefinition Width="*" />
   </Grid.ColumnDefinitions>
   <Button x:Name="submitButton" Content="Submit"
            Margin="0,40,0,0"
            MinWidth="250"
            Grid.Column="0"/>
    <Button x:Name="annulerButton" Content="Cancel"
            Margin="5,40,0,0"
            MinWidth="250"
            Grid.Column="1"/>
</Grid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM