Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

wpf - DataGridComboBoxColumn cell not displaying selected item text?

I was wondering how you get the DataGridComboBoxColumn to display the selected item text when it is not in editing mode? And also is it possible to make it so the combo box in edit mode displays the selected item text initially?

Here is my XAML:

<DataGridComboBoxColumn Header="Formatter" 
                        SelectedItemBinding="{Binding Path=Format}">
  <DataGridComboBoxColumn.ElementStyle>
    <Style TargetType="">
      <Setter Property="Text" Value="{Binding Path=FormatView.Name}" />
    </Style>
  </DataGridComboBoxColumn.ElementStyle>
  <DataGridComboBoxColumn.EditingElementStyle>
    <Style TargetType="ComboBox">
      <Setter Property="ItemsSource" Value="{Binding Path=DefinedFormatters}" />
      <Setter Property="IsDropDownOpen" Value="True" />
      <Setter Property="ItemTemplate">
        <Setter.Value>
          <DataTemplate>
            <TextBlock Text="{Binding Path=Name}"></TextBlock>
          </DataTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This was the only resource on DataGridComboBoxColumn that I found helpful:

http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridcomboboxcolumn.aspx

Everything else (that I found on non-MSDN sites) was misleading!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...