Uwp 如何确保所有控件在白画布中可见

Uwp 如何确保所有控件在白画布中可见,uwp,uwp-xaml,Uwp,Uwp Xaml,我做了以下工作: 我创建一个空白页 将白色画布放大66.67%,以便我可以更清楚地看到控件的位置 我从工具箱中拖动按钮,在每个角落放置4个按钮 问题: a) 使用LocalMachine模式运行应用程序 3个按钮不可见 except this button. <Button x:Name="button1" Content="Button" HorizontalAlignment="Left" Margin="47,69,0,0" VerticalAlignment="Top" Hei

我做了以下工作:

  • 我创建一个空白页

  • 将白色画布放大66.67%,以便我可以更清楚地看到控件的位置

  • 我从工具箱中拖动按钮,在每个角落放置4个按钮

    问题:

  • a) 使用LocalMachine模式运行应用程序

    3个按钮不可见

    except this button.
    
     <Button x:Name="button1" Content="Button" HorizontalAlignment="Left" Margin="47,69,0,0" VerticalAlignment="Top" Height="70" Width="193"/>
    
    除了这个按钮。
    
    b) 使用模拟器模式运行应用程序

    问题:

    只有左上角和右上角可见

    左下角和右下角不可见

    问题:

    为什么所有按钮都放在白色画布中,而不是所有按钮都可见

    你需要做什么?下面是空白页,你可以试着让我知道我做错了什么

    谢谢你的帮助

    <Page
        x:Class="w10QMgmt.BlankPage3"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:w10QMgmt"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="1201,88,0,0" VerticalAlignment="Top" Height="60" Width="151"/>
            <Button x:Name="button1" Content="Button" HorizontalAlignment="Left" Margin="47,69,0,0" VerticalAlignment="Top" Height="70" Width="193"/>
            <Button x:Name="button2" Content="Button" HorizontalAlignment="Left" Margin="1139,832,0,0" VerticalAlignment="Top" Height="88" Width="183"/>
            <Button x:Name="button3" Content="Button" HorizontalAlignment="Left" Margin="58,844,0,0" VerticalAlignment="Top" Height="52" Width="143"/>
    
        </Grid>
    </Page>
    
    
    
    1)您已将所有按钮放在网格控件中,没有使用画布

    2) 您已经根据边距设置了所有按钮的位置-通过鼠标放置它们-永远不要这样做,除非您知道自己在做什么以及生成的代码意味着什么

    3) 更改窗口/页面大小不会影响按钮的位置-因为它们的位置基于边距-从左侧和顶部的距离-在这种情况下永远不会更改

    要正确执行此操作(如果希望在窗口的四个角中放置4个按钮),只需删除边距-并将水平和垂直对齐设置为正确的角:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Button x:Name="button" Content="Button" HorizontalAlignment="Left"  VerticalAlignment="Top" Height="60" Width="151"/>
        <Button x:Name="button1" Content="Button" HorizontalAlignment="Right" VerticalAlignment="Top" Height="70" Width="193"/>
        <Button x:Name="button2" Content="Button" HorizontalAlignment="Left"  VerticalAlignment="Bottom" Height="88" Width="183"/>
        <Button x:Name="button3" Content="Button" HorizontalAlignment="Right"  VerticalAlignment="Bottom" Height="52" Width="143"/>
    </Grid>
    
    
    
    现在,当窗口/页面大小更改时,它们的位置将更新-因为网格大小将更改,并且其内部的所有子位置都将更新-因为位置现在相对设置了

    1)您已将所有按钮放置在网格控件中,没有使用画布

    2) 您已经根据边距设置了所有按钮的位置-通过鼠标放置它们-永远不要这样做,除非您知道自己在做什么以及生成的代码意味着什么

    3) 更改窗口/页面大小不会影响按钮的位置-因为它们的位置基于边距-从左侧和顶部的距离-在这种情况下永远不会更改

    要正确执行此操作(如果希望在窗口的四个角中放置4个按钮),只需删除边距-并将水平和垂直对齐设置为正确的角:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Button x:Name="button" Content="Button" HorizontalAlignment="Left"  VerticalAlignment="Top" Height="60" Width="151"/>
        <Button x:Name="button1" Content="Button" HorizontalAlignment="Right" VerticalAlignment="Top" Height="70" Width="193"/>
        <Button x:Name="button2" Content="Button" HorizontalAlignment="Left"  VerticalAlignment="Bottom" Height="88" Width="183"/>
        <Button x:Name="button3" Content="Button" HorizontalAlignment="Right"  VerticalAlignment="Bottom" Height="52" Width="143"/>
    </Grid>
    
    
    

    现在他们的位置会随着窗口/页面大小的改变而更新-因为网格大小会改变,它里面的所有子位置都会更新-因为位置现在相对设置了

    对于我自己,我喜欢相对面板,只使用边距进行小的推拉

    <Grid>
        <RelativePanel>
            <Button Name="1"
                    RelativePanel.AlignTopWithPanel="True"
                    RelativePanel.AlignLeftWithPanel="True"/>
            <Button Name="2"
                    RelativePanel.AlignTopWithPanel="True"
                    RelativePanel.AlignRightWithPanel="True"/>
            <Button Name="3"
                    RelativePanel.AlignBottomWithPanel="True"
                    RelativePanel.AlignLeftWithPanel="True"/>
            <Button Name="4"
                    RelativePanel.AlignBottomWithPanel="True"
                    RelativePanel.AlignRightWithPanel="True"/>
        </RelativePanel>
    </Grid>
    
    
    

    还有@RTdev所说的,请学习一些教程,win 10的UWP对于布局和如何使用布局来说是一个很好的开始。

    对于我自己,我很喜欢RelativePanel,只使用边距进行小的推拉

    <Grid>
        <RelativePanel>
            <Button Name="1"
                    RelativePanel.AlignTopWithPanel="True"
                    RelativePanel.AlignLeftWithPanel="True"/>
            <Button Name="2"
                    RelativePanel.AlignTopWithPanel="True"
                    RelativePanel.AlignRightWithPanel="True"/>
            <Button Name="3"
                    RelativePanel.AlignBottomWithPanel="True"
                    RelativePanel.AlignLeftWithPanel="True"/>
            <Button Name="4"
                    RelativePanel.AlignBottomWithPanel="True"
                    RelativePanel.AlignRightWithPanel="True"/>
        </RelativePanel>
    </Grid>
    
    
    

    还有@RTdev所说的,请学习一些教程,win 10的UWP是布局和如何使用布局的一个很好的开始。

    我不太了解UWP的UI设计方法。白色矩形是网格。请帮忙。如何根据我想要的位置在网格中的任意位置放置控件?当我将工具箱中的任何控件拖动到网格上时,它将自动具有边距。只需阅读一些教程。。。在网格中,可以通过设置控件的水平/垂直对齐来放置控件,使其保持右边缘,可以创建列和行,然后将控件放置在所需的行/列中。如果希望控件始终处于同一位置,请使用Canvas并设置Canvas.Left和Canvas.Top属性,但请记住在窗口/页面大小更改时更新它们。您的问题是,您将按钮放置在1201像素上,然后运行窗口宽度小于1201像素的应用程序,您想知道为什么它不可见?我认为很难找到Win10 UI设计教程。但我想,我在尝试了几次之后,根据你的建议——使用html方法行和列。更新窗口/页面大小更改是什么意思?现在我使用行和列来定位控件。请详细说明。当您在Visual Studio中使用designer时,它以一定的宽度和高度显示您的视图(您可以使用DesignWidth和DesignHeight进行设置),当您在设备上运行应用程序时-窗口大小为全屏(宽度和高度取决于设备)或者处于窗口状态-您可以根据需要更改其宽度和高度。如果您找不到windows 10教程-搜索win rt/win 8/wpf/silverlight的教程-int简单容器控件(网格、画布、stackpanel等)的问题,它们将是90%相同的。您需要了解它们如何定位内容。最后,我使用行和列方法来显示控件。谢谢,我真的不了解UWP的UI设计方法。白色矩形是网格。请帮忙。如何根据我想要的位置在网格中的任意位置放置控件?当我将工具箱中的任何控件拖动到网格上时,它将自动具有边距。只需阅读一些教程。。。在网格中,可以通过设置控件的水平/垂直对齐来放置控件,使其保持右边缘,可以创建列和行,然后将控件放置在所需的行/列中。如果希望控件始终处于同一位置,请使用Canvas并设置Canvas.Left和Canvas.Top属性,但请记住在窗口/页面大小更改时更新它们。您的问题是,您将按钮放置在1201像素上,然后运行窗口宽度小于1201像素的应用程序,您想知道为什么它不可见?我认为很难找到Win10 UI设计教程。但我想,我在尝试了几次之后,根据你的建议——使用html方法行和列。你是什么意思