2016-02-15 93 views
2

我正在使用嵌套網格。在主網格中我有兩個單選按鈕,而在第二個時,我有兩個額外的單選按鈕和其他控件。WPF上嵌套網格問題

我希望總網格將包含3行和3列。

相關的代碼是:

<xctk:WizardPage Name="Page3" PageType="Interior" 
      Title="Stages" 
      Background="#FF27E0E0"> 
     <xctk:WizardPage.CanSelectNextPage> 
      <MultiBinding Converter="{StaticResource NextFromPage3}"> 
       <Binding ElementName="HR" Path="IsChecked" Mode="OneWay"/> 
       <Binding ElementName="LR" Path="IsChecked" Mode="OneWay"/> 
       <Binding ElementName="yes" Path="IsChecked" Mode="OneWay"/> 
       <Binding ElementName="no" Path="IsChecked" Mode="OneWay"/> 
      </MultiBinding> 
     </xctk:WizardPage.CanSelectNextPage> 

     <Grid ShowGridLines="True" Margin="-5 -10"> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="Auto"/> 
      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="Auto"/> 
       <ColumnDefinition Width="*"/> 
       <ColumnDefinition Width="*"/> 
      </Grid.ColumnDefinitions> 
      <Label x:Name="qual" Content="Select Quality:" FontSize="13.333" Margin="5 10" VerticalAlignment="Top" HorizontalAlignment="Left"/> 
      <RadioButton x:Name="HR" Content="High-Resolution" FontSize="13.333" Grid.Column="1" Margin="5 10" VerticalAlignment="Top"/> 
      <RadioButton x:Name="LR" FontSize="13.333" Content="Low-Resolution" Grid.Column="2" Margin="5 10" VerticalAlignment="Top"/> 
      <Grid Grid.Row="1"> 
       <Grid.Visibility> 
        <MultiBinding Converter="{StaticResource FilterConverter}"> 
         <Binding ElementName ="HR" Path="IsChecked" Mode="OneWay"/> 
         <Binding ElementName ="LR" Path="IsChecked" Mode="OneWay"/> 
        </MultiBinding> 
       </Grid.Visibility> 
       <Label x:Name="symbol" Content="Select Symbol:" Grid.Row ="1" Grid.Column="0" FontSize="13.333" Margin="5 10" VerticalAlignment="Top" HorizontalAlignment="Left"/> 
       <ComboBox x:Name="symbolsCmbBox" FontSize="13.333" Grid.Row="1" Grid.Column="1" Margin="5 10" VerticalAlignment="Top" HorizontalAlignment="Left" ItemTemplate="{StaticResource cmbTemplate}" IsSynchronizedWithCurrentItem="True" SelectedIndex="0"> 
        <ComboBox.ItemsSource> 
         <MultiBinding Converter="{StaticResource SymbolComboboxItemsFilter}"> 
          <Binding ElementName ="HR" Path="IsChecked" Mode="OneWay"/> 
          <Binding ElementName ="LR" Path="IsChecked" Mode="OneWay"/> 
         </MultiBinding> 
        </ComboBox.ItemsSource> 
       </ComboBox> 
       <Label x:Name="isExists" Content="Select Yes if process will perform:" Grid.Row ="2" FontSize="13.333" Margin="5 10" VerticalAlignment="Top" HorizontalAlignment="Left"/> 
       <RadioButton x:Name="yes" Content="Yes" FontSize="13.333" Grid.Row="2" Grid.Column="1" Margin="5 10" VerticalAlignment="Top"/> 
       <RadioButton x:Name="no" Content="No" FontSize="13.333" Grid.Row="2" Grid.Column="2" Margin="5 10" VerticalAlignment="Top"/> 
      </Grid> 
     </Grid> 

上面的代碼是上WPF工具包是否存在嚮導的一部分。 我的問題與嵌套網格上方該控件不位於預期位置。 雖然我只使用一個主網架,這個問題沒有發生,但我需要從其他原因嵌套格..

編輯,第一個答案: 我想,主要的電網將是第一線(3列),內部網格將從第二行開始,將包含總共兩行(3列),所以如何指定它?

EDIT-用於第二答案:

第一行(主網格)不是直的與第二和第三行(內網格) - 好像主電網的兩個無線電按鈕僅定位在列= 2上,即使它看起來不是來自xaml代碼。現在我的代碼就像下面第二個答案中出現的一樣。

感謝您的諮詢!

回答

2

您試圖在內部網格上使用Grid.Row和Grid.Column,但沒有指定RowDefinitions或ColumnDefinitions。如果您希望網格的子節點能夠位於特定位置,則需要爲內部網格指定它們。

編輯:提供我明白你當前的要求,你想要一個2x3網格開始內部,在第二行的3x3網格。 (你可能只需要一個2×3的網格,但是讓我們來處理你的問題。)

你需要上面提到的行和列的定義,但是你還需要做另外兩件事。 1.確保您的孩子的Grid.Row分別設置爲0和1,而不是1和2,以便它們與內部網格重合。 2.確保內部網格使用2行的跨度和3列的跨度來填充外部網格擁有的區域。

它應該是這個樣子:(編輯行和列的定義,如果你需要特定的大小)

<Grid ShowGridLines="True" Margin="-5 -10"> 
    <Grid.RowDefinitions> 
    <RowDefinition Height="Auto"/> 
    <RowDefinition Height="Auto"/> 
    <RowDefinition Height="Auto"/> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
    <ColumnDefinition Width="Auto"/> 
    <ColumnDefinition Width="*"/> 
    <ColumnDefinition Width="*"/> 
    </Grid.ColumnDefinitions> 
    <Label x:Name="qual" Content="Select Quality:" FontSize="13.333" Margin="5 10" VerticalAlignment="Top" HorizontalAlignment="Left"/> 
    <RadioButton x:Name="HR" Content="High-Resolution" FontSize="13.333" Grid.Column="1" Margin="5 10" VerticalAlignment="Top"/> 
    <RadioButton x:Name="LR" FontSize="13.333" Content="Low-Resolution" Grid.Column="2" Margin="5 10" VerticalAlignment="Top"/> 
    <Grid Grid.Row="1" Grid.RowSpan="2" Grid.ColumnSpan="3"> 
    <Grid.RowDefinitions> 
     <RowDefinition/> 
     <RowDefinition/> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition/> 
     <ColumnDefinition/> 
     <ColumnDefinition/> 
    </Grid.ColumnDefinitions> 
    <Grid.Visibility> 
     <MultiBinding Converter="{StaticResource FilterConverter}"> 
     <Binding ElementName ="HR" Path="IsChecked" Mode="OneWay"/> 
     <Binding ElementName ="LR" Path="IsChecked" Mode="OneWay"/> 
     </MultiBinding> 
    </Grid.Visibility> 
    <Label x:Name="symbol" Content="Select Symbol:" Grid.Row ="0" Grid.Column="0" FontSize="13.333" Margin="5 10" VerticalAlignment="Top" HorizontalAlignment="Left"/> 
    <ComboBox x:Name="symbolsCmbBox" FontSize="13.333" Grid.Row="0" Grid.Column="1" Margin="5 10" VerticalAlignment="Top" HorizontalAlignment="Left" IsSynchronizedWithCurrentItem="True" SelectedIndex="0"> 
     <ComboBox.ItemsSource> 
     <MultiBinding Converter="{StaticResource SymbolComboboxItemsFilter}"> 
      <Binding ElementName ="HR" Path="IsChecked" Mode="OneWay"/> 
      <Binding ElementName ="LR" Path="IsChecked" Mode="OneWay"/> 
     </MultiBinding> 
     </ComboBox.ItemsSource> 
    </ComboBox> 
    <Label x:Name="isExists" Content="Select Yes if process will perform:" Grid.Row ="1" FontSize="13.333" Margin="5 10" VerticalAlignment="Top" HorizontalAlignment="Left"/> 
    <RadioButton x:Name="yes" Content="Yes" FontSize="13.333" Grid.Row="1" Grid.Column="1" Margin="5 10" VerticalAlignment="Top"/> 
    <RadioButton x:Name="no" Content="No" FontSize="13.333" Grid.Row="1" Grid.Column="2" Margin="5 10" VerticalAlignment="Top"/> 
    </Grid> 
</Grid> 
+0

我編輯question-我想,主要的電網將成爲第一行(3列)和內網將從第二行開始並將包含總共兩行(3列),所以如何指定它? – Programmer

2

指定的行數和列數網格嵌套指的是網格嵌套不是父主網。您需要定義網格如下所示:

<Grid ShowGridLines="True" Margin="-5 -10"> 
<Grid.RowDefinitions> 
    <RowDefinition Height="Auto"/> 
    <RowDefinition Height="Auto"/> 
    <RowDefinition Height="Auto"/> 
</Grid.RowDefinitions> 
<Grid.ColumnDefinitions> 
    <ColumnDefinition Width="Auto"/> 
    <ColumnDefinition Width="*"/> 
    <ColumnDefinition Width="*"/> 
</Grid.ColumnDefinitions> 
<Label x:Name="qual" Content="Select Quality:" FontSize="13.333" Margin="5 10" VerticalAlignment="Top" HorizontalAlignment="Left"/> 
<RadioButton x:Name="HR" Content="High-Resolution" FontSize="13.333" Grid.Column="1" Margin="5 10" VerticalAlignment="Top"/> 
<RadioButton x:Name="LR" FontSize="13.333" Content="Low-Resolution" Grid.Column="2" Margin="5 10" VerticalAlignment="Top"/> 
<Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="Auto"/> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="Auto"/> 
     <ColumnDefinition Width="*"/> 
     <ColumnDefinition Width="*"/> 
    </Grid.ColumnDefinitions> 
    <Grid.Visibility> 
     <MultiBinding Converter="{StaticResource FilterConverter}"> 
      <Binding ElementName ="HR" Path="IsChecked" Mode="OneWay"/> 
      <Binding ElementName ="LR" Path="IsChecked" Mode="OneWay"/> 
     </MultiBinding> 
    </Grid.Visibility> 
    <Label x:Name="symbol" Content="Select Symbol:" Grid.Row ="0" Grid.Column="0" FontSize="13.333" Margin="5 10" VerticalAlignment="Top" HorizontalAlignment="Left"/> 
    <ComboBox x:Name="symbolsCmbBox" FontSize="13.333" Grid.Row="1" Grid.Column="1" Margin="5 10" VerticalAlignment="Top" HorizontalAlignment="Left" ItemTemplate="{StaticResource cmbTemplate}" IsSynchronizedWithCurrentItem="True" SelectedIndex="0"> 
     <ComboBox.ItemsSource> 
      <MultiBinding Converter="{StaticResource SymbolComboboxItemsFilter}"> 
       <Binding ElementName ="HR" Path="IsChecked" Mode="OneWay"/> 
       <Binding ElementName ="LR" Path="IsChecked" Mode="OneWay"/> 
      </MultiBinding> 
     </ComboBox.ItemsSource> 
    </ComboBox> 
    <Label x:Name="isExists" Content="Select Yes if process will perform:" Grid.Row ="1" FontSize="13.333" Margin="5 10" VerticalAlignment="Top" HorizontalAlignment="Left"/> 
    <RadioButton x:Name="yes" Content="Yes" FontSize="13.333" Grid.Row="1" Grid.Column="1" Margin="5 10" VerticalAlignment="Top"/> 
    <RadioButton x:Name="no" Content="No" FontSize="13.333" Grid.Row="1" Grid.Column="2" Margin="5 10" VerticalAlignment="Top"/> 
</Grid> 

+0

它不能解決我的問題 - 內部網格現在實際上從第二行開始(這很好),但它只伸展在第一列,而不是第二和第三列。我相應地編輯了我的問題。任何想法? – Programmer

+0

要使內部網格伸展並佔據主網格的所有3列,我們需要指定Grid.ColumnSpan =「3」。 –