2017-03-23 88 views
0

我正在研究一個小型單頁c#UWP應用程序。當我在設計視圖中看它時,一切看起來都不錯,沒有不必要的空白。但是當我運行它時,窗戶在整個設計周圍有一個很大的空白空間,看起來很糟糕。下面我包含了設計和運行窗口的截圖。我怎樣才能刪除這個多餘的空白空間?運行時項目周圍不必要的空白空間

設計視圖(沒有怪異的白色空間):

Design view, no weird white space

運行(怪異的白色空間):

Running, weird white space

應用程序窗口是相當小的,400x200。我試着改變這些值,但它所做的一切是一起擠壓控件並在邊界周圍添加更多空白區域。

編輯:顯然儘管設計視圖很好,這是我的XAML的問題,所以在這裏你去。

<Page x:Class="ReservationManager.Views.StartPage" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:local="using:ReservationManager.Views" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     mc:Ignorable="d" 
     DataContext="{Binding StartPageInstance, Source={StaticResource Locator}}" 
     Width="400" 
     Height="200"> 

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*" /> 
      <ColumnDefinition Width="*" /> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition /> 
      <RowDefinition /> 
      <RowDefinition /> 
     </Grid.RowDefinitions> 

     <Grid Grid.Row="0"> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="*" /> 
       <ColumnDefinition Width="*" /> 
      </Grid.ColumnDefinitions> 
      <TextBlock Name="Label1" 
         VerticalAlignment="Center" 
         HorizontalAlignment="Center" 
         Text="Label 1: " 
         FontFamily="Segoe UI Historic" /> 
      <TextBox Grid.Column="1" 
        VerticalAlignment="Center" 
        Name="TextBox1" 
        MaxLength="7" 
        Text="{Binding tb1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> 
     </Grid> 

     <Grid Grid.Row="0" 
       Grid.Column="1"> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="*" /> 
       <ColumnDefinition Width="*" /> 
      </Grid.ColumnDefinitions> 
      <TextBlock Grid.Column="0" 
         Name="Label2" 
         VerticalAlignment="Center" 
         HorizontalAlignment="Center" 
         Text="Label 2: " 
         Margin="10,0,0,0" 
         FontFamily="Segoe UI Historic" /> 
      <TextBox Grid.Column="1" 
        VerticalAlignment="Center" 
        Name="TextBox2" 
        Text="{Binding tb2, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> 
     </Grid> 

     <Grid Grid.Row="1" 
       Grid.Column="0"> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="*" /> 
       <ColumnDefinition Width="*" /> 
      </Grid.ColumnDefinitions> 
      <TextBlock Grid.Column="0" 
         Name="Label3" 
         VerticalAlignment="Center" 
         HorizontalAlignment="Center" 
         Text="Label 3: " 
         FontFamily="Segoe UI Historic" /> 
      <ComboBox Grid.Column="1" 
         VerticalAlignment="Center" 
         Name="Dropdown" 
         ItemsSource="{Binding cb}" 
         SelectedValue="{Binding cb1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
         DisplayMemberPath="Name" /> 
     </Grid> 

     <StackPanel VerticalAlignment="Center" 
        HorizontalAlignment="Center" 
        Grid.Row="1" 
        Grid.Column="1"> 
      <RadioButton IsChecked="{Binding IsReserveChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
         GroupName="Radio" 
         Content="radio1" /> 
      <RadioButton IsChecked="{Binding IsUnreserveChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
         GroupName="Radio" 
         Content="radio2" /> 
     </StackPanel> 

     <TextBlock Grid.Row="2" 
        Grid.Column="0" 
        VerticalAlignment="Center" 
        HorizontalAlignment="Center" 
        Foreground="Red"> 
      Warning: ---- 
     </TextBlock> 

     <Button Grid.Row="2" 
       Grid.Column="1" 
       HorizontalAlignment="Center" 
       VerticalAlignment="Center" 
       Content="Execute" 
       Command="{Binding ExecuteCommand}" /> 
    </Grid> 
</Page> 
+0

不能完全確定你想要的這裏,但網格採取所有可用的空間,並給予你的佈局和事實的控件全部在每個網格單元的中心對齊,它們之間的空白空間應該是可以預料的! –

回答

1

問題正在由「首選最小尺寸」造成被缺省設置過高。

添加下面一行的後面的代碼固定的問題:

ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size { Width = 250, Height = 200 });