网格中的ComboBox无法填充网格的单元格宽度

时间:2019-07-15 22:36:59

标签: xaml uwp uwp-xaml datagridcell

我在import React from 'react'; import PropTypes from 'prop-types'; export default class Card extends PureComponent { static propTypes = { title: PropTypes.string, // other props onClick: PropTypes.func.isRequired, } // other things in this class render() { const { onClick, title } = this.props; return ( <div onClick={onClick}> <h1>{title}</h1> </div> ) } } 中有一个ComboBox以及几个文本框。
Grid的定义如下:

Grid

请注意,我已经在<Grid Grid.Row="1" Grid.Column="1" Margin="0,10,0,0" ColumnSpacing="5"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <!-- All of the text boxes --> <TextBlock Grid.Column="8" Text="Combo" VerticalAlignment="Center" /> <ComboBox Grid.Column="9" Text="{x:Bind ViewModel.ComboText}" ItemsSource="{x:Bind ViewModel.ComboItems}" HorizontalContentAlignment="Stretch" /> </Grid> 中添加了。这不会使组合填充HorizontalContentAlignment,但仍然看起来像这样:

enter image description here

如何使Grid填充ComboBox的宽度,使其与其他Cell一样?

1 个答案:

答案 0 :(得分:0)

  

网格中的组合框无法填充网格的单元格宽度

HorizontalContentAlignment用于使控件的内容水平对齐。如果要使ComboBox填充网格单元格,请将HorizontalAlignment设置为Stretch

<ComboBox Grid.Column="9" 
Text="{x:Bind ViewModel.ComboText}" 
ItemsSource="{x:Bind ViewModel.ComboItems}" 
HorizontalAlignment="Stretch" />