Use converter on bound items in combobox

前端 未结 1 887
广开言路
广开言路 2020-12-25 11:07

i have a combobox which is bound to a datatable column like this:

ComboBox.DataContext = DataDataTable;                
ComboBox.DisplayMemberPath = DataData         


        
相关标签:
1条回答
  • 2020-12-25 12:03

    You can modify the ItemTemplate of the ComboBox and use your converter:

    <ComboBox ItemsSource="{Binding}">
      <ComboBox.ItemTemplate>
        <DataTemplate>
          <TextBlock Text="{Binding Converter={StaticResource IDPrefixValueConverter}}"/>
        </DataTemplate>
      </ComboBox.ItemTemplate>
    </ComboBox>
    

    Each item is bound to the items in the ItemsSource. By using the converter in the binding you are able to perform the conversion you want.

    0 讨论(0)
提交回复
热议问题