2016-08-22 101 views
1

我正在制作一个应用程序,我希望某些网格行和列要修复,而其他的要调整大小以适应窗口。我的问题是我无法在Universal Apps中执行此操作。在UWP中制作固定宽度的网格列和行

在WPF中,解决方法很简单:

<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="50" /> <!-- This row is a fixed height --> 
     <RowDefinition Height="*" MinHeight="200" /> <!-- This row is resizeable, but has a minimum height --> 
     <RowDefinition Height="100" /> 
     <RowDefinition Height="20" /> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="20" /> <!-- This column has a fixed width --> 
     <ColumnDefinition Width="*" MinWidth="300" /> <!-- These rows are resizeable, but have minimum widths --> 
     <ColumnDefinition Width="*" MinWidth="300" /> 
     <ColumnDefinition Width="20" /> 
    </Grid.ColumnDefinitions> 
</Grid> 

当我尝试这UWP,行和列的固定尺寸调整,同时有星号的其他人保持固定。我试着在固定的行和列上放置星号,并删除了预先存在的行。我认为在UWP中它被颠倒过来了,但是这严重地搞砸了我的应用程序,并使其变得更糟。

我的解决办法是尝试在UWP如下:

<Grid x:Name="pageGrid" 
     Background="White"> 
    <Grid.RowDefinitions> 
     <RowDefinition MaxHeight="20" 
         MinHeight="20"/> 
     <RowDefinition Height="*"/> 
     <RowDefinition MaxHeight="20" 
         MinHeight="20"/> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition MaxWidth="20" 
          MinWidth="20"/> 
     <ColumnDefinition Width="*"/> 
     <ColumnDefinition MaxWidth="260" 
          MinWidth="260"/> 
     <ColumnDefinition MaxWidth="20" 
          MinWidth="20"/> 
    </Grid.ColumnDefinitions> 
</Grid> 

的这里想法是有固定的利润在我的控制,在20个像素宽度。这些边缘内有两个框:一个宽度固定,可调整高度,另一个调整两个方向。

尽管如此,我再次遇到同样的问题,其中边距调整大小,但'可调整大小'框不。

实际上有一种方法可以使用通用Windows平台在网格中拥有固定的和可调整大小的行和列吗?到目前为止,我还没有找到这方面的证据。

完整代码:

<Page 
    x:Class="UniversalCamera.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:UniversalCamera" 
    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}" 
      MinWidth="800" 
      MinHeight="450" 
      Width="800" 
      Height="450"> 
     <Grid x:Name="pageGrid" 
       Background="White"> 
      <Grid.RowDefinitions> 
       <RowDefinition MaxHeight="20" 
           MinHeight="20"/> 
       <RowDefinition Height="*"/> 
       <RowDefinition MaxHeight="20" 
           MinHeight="20"/> 
      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition MaxWidth="20" 
            MinWidth="20"/> 
       <ColumnDefinition Width="*"/> 
       <ColumnDefinition MaxWidth="260" 
            MinWidth="260"/> 
       <ColumnDefinition MaxWidth="20" 
            MinWidth="20"/> 
      </Grid.ColumnDefinitions> 
      <Border BorderThickness="2" 
        BorderBrush="Black" 
        CornerRadius="5" 
        Grid.Column="1" 
        Grid.Row="1" 
        Grid.ColumnSpan="2" 
        Margin="-10,-10,-10,-10"/> 
      <Border BorderThickness="2" 
        BorderBrush="Black" 
        CornerRadius="5" 
        Grid.Column="1" 
        Grid.Row="1" 
        Margin="2,2,2,2"> 
       <Image x:Name="imageFrame" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch"/> 
      </Border> 
      <Canvas x:Name="controlCanvas" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch" 
        Grid.Column="2" 
        Grid.Row="1"> 
       <StackPanel x:Name="controlStack" 
          Canvas.Top="0" 
          Canvas.Left="0" 
          Width="260" 
          Orientation="Vertical"> 
        <Button x:Name="startLiveButton" 
          Width="200" 
          Margin="0,5,0,0" 
          HorizontalAlignment="Center" 
          Content="Start Live" 
          Click="startLiveButton_Click"/> 
        <Button x:Name="stopLiveButton" 
          Width="200" 
          Margin="0,5,0,0" 
          HorizontalAlignment="Center" 
          Content="Stop Live" 
          Click="stopLiveButton_Click"/> 
        <Button x:Name="freezeVideoButton" 
          Width="200" 
          Margin="0,5,0,0" 
          HorizontalAlignment="Center" 
          Content="Freeze Video" 
          Click="freezeVideoButton_Click"/> 
        <Button x:Name="loadParameterButton" 
          Width="200" 
          Margin="0,5,0,0" 
          HorizontalAlignment="Center" 
          Content="Load Parameter" 
          Click="loadParameterButton_Click"/> 
        <CheckBox x:Name="autoWhiteCheckbox" 
           HorizontalAlignment="Center" 
           Width="200" 
           Margin="0,25,0,0" 
           Content="Auto White Balance" 
           Checked="autoWhiteCheckbox_Checked" 
           Unchecked="autoWhiteCheckbox_Unchecked"/> 
        <CheckBox x:Name="autoGainCheckbox" 
           HorizontalAlignment="Center" 
           Width="200" 
           Margin="0,5,0,0" 
           Content="Auto Gain Balance" 
           Checked="autoGainCheckbox_Checked" 
           Unchecked="autoGainCheckbox_Unchecked"/> 
       </StackPanel> 
      </Canvas> 
     </Grid> 
    </Grid> 
</Page> 

此代码是为了有额外的行和列围绕主控制利润率。这些应该固定在20像素。当我运行这些代码时,利润率会拉大,而中央框则保持不变;这是我所预期的相反:(黑色的轮廓区域停留时,窗口大小,而利润被拉伸以适应窗口大小相同)

enter image description here enter image description here

+0

在网格的定义看,似乎秩序。就网格工作方式而言,UWP与WPF的行为方式相同,因此应该没有问题/差异。我使用你的网格声明创建了一个测试,它看起来像预期的那样延伸。你能发布你的完整代码吗? – AlexDrenea

+0

@AlexDrenea完整代码已添加到问题 –

+0

那么页面的问题是什么?看起来/延伸对我来说是正确的。边框是固定的,“屏幕”放大,侧面的按钮固定。 – AlexDrenea

回答

2

你的主网架是固定的在800×450像素。如果删除该限制,电网将延伸适当

Stretched UI

更新代码:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" 
     MinWidth="800" 
     MinHeight="450"> 
    <Grid x:Name="pageGrid" 
... 
+0

被如此简单的东西击败... –