0

在下面的 XAML 中,组合框不可见。我究竟做错了什么?

<Grid>
  <StackPanel>
    <ComboBox Name="combo1"
              ItemsSource="{Binding}"
              DisplayMemberPath="PartNumber" />
  </StackPanel>
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition></RowDefinition>
      <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition></ColumnDefinition>
      <ColumnDefinition></ColumnDefinition>
    </Grid.ColumnDefinitions>

    <TextBlock Grid.Row="0"
               Grid.Column="0"
               Text="{Binding ElementName=combo1, Path=SelectedItem.PartName}"
               Background="AliceBlue" />
    <TextBlock Grid.Row="0"
               Grid.Column="1"
               Text="{Binding ElementName=combo1, Path=SelectedItem.PartQuantity}"
               Background="Beige" />
  </Grid>
</Grid>
4

1 回答 1

1

您已将网格放置在导致问题的组合框上方,您可以为组合放置新行或使用画布指定 zIndex。请查看下面的 xaml 部分。

<Canvas>
  <ComboBox Canvas.ZIndex="2"
            Width="300"
            Name="combo1"
            ItemsSource="{Binding}"
            DisplayMemberPath="PartNumber" />

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition></RowDefinition>
      <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition></ColumnDefinition>
      <ColumnDefinition></ColumnDefinition>
    </Grid.ColumnDefinitions>

    <TextBlock Grid.Row="0"
               Grid.Column="0"
               Text="{Binding ElementName=combo1, Path=SelectedItem.PartName}"
               Background="AliceBlue" />
    <TextBlock Grid.Row="0"
               Grid.Column="1"
               Text="{Binding ElementName=combo1, Path=SelectedItem.PartQuantity}"
               Background="Beige" />
  </Grid>
</Canvas>
于 2013-01-22T14:48:15.433 回答