2

我想在数据网格中显示一个下拉列表,用户可以从中选择不同的值。不知何故,我无法显示一个 ComboBox,而是只显示该值,就好像它是一个普通的 TextColumn。下面是我的代码,

<StackPanel Grid.Row="0">
            <toolkit:DataGrid Name="definitionGrid" Margin="0,10,0,0" AutoGenerateColumns="False" 
                                              CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True"
                                              RowHeight="25" FontWeight="Normal" ItemsSource="{Binding Profile}"
                                              SelectionMode="Single" ScrollViewer.HorizontalScrollBarVisibility="Auto" Width="450"
                              ScrollViewer.VerticalScrollBarVisibility="Auto" Height="200">
                <toolkit:DataGrid.Columns>
                    <toolkit:DataGridTextColumn Header="Name" Width="80" Binding="{Binding Name}" CellStyle="{StaticResource cellCenterAlign}"/>
                    <toolkit:DataGridComboBoxColumn Header="Gender" Width="220" SelectedItemBinding="{Binding Gender}" ItemsSource="{Binding Source={StaticResource GenderValues}}" CellStyle="{StaticResource cellCenterAlign}"/>
                    <toolkit:DataGridCheckBoxColumn Header="Email" Width="60" Binding="{Binding ReceivesEmail}" CellStyle="{StaticResource cellCenterAlign}"/>
                    <toolkit:DataGridTextColumn Header="Others" Width="80" CellStyle="{StaticResource cellCenterAlign}"/>
                </toolkit:DataGrid.Columns>
            </toolkit:DataGrid>   
       </StackPanel>
4

1 回答 1

3

DataGridComboBoxColumn 仅在处于编辑模式时才显示 ComboBox;否则它会像普通的 DataGridTextColumn 一样显示。如果要显示 ComboBox,可以定义 DataGridTemplateColumn:

<DataGridTemplateColumn Header="Gender">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox Width="220" SelectedItem="{Binding Gender}" ItemsSource="{Binding Source={StaticResource GenderValues}}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
于 2010-06-02T07:23:16.953 回答