我有以下ComboBox
<ComboBox x:Name="TaskText" Text="{Binding TaskNameBinding}" ItemsSource="{Binding
taskList, ElementName=MainWin}" SelectedValuePath="_id" DisplayMemberPath="_name"
Background="Yellow" Padding="0" Margin="0" BorderThickness="0" Width="90"/>
我希望将Text Wrapping应用于此组合框并按照代码片段here
进行操作<ComboBox x:Name="TaskText" ItemsSource="{Binding taskList, ElementName=MainWin}"
SelectedValuePath="_id" DisplayMemberPath="_name" Background="Yellow" Padding="0"
Margin="0" BorderThickness="0" Width="90">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding TaskNameBinding}"
TextTrimming="CharacterEllipsis" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
但是这个模板打破了绑定,组合框没有显示任何值。任何帮助将不胜感激
答案 0 :(得分:6)
想出来
<ComboBox x:Name="TaskText" Text="{Binding TaskNameBinding}" ItemsSource="{Binding taskList, ElementName=MainWin}" SelectedValuePath="_id" DisplayMemberPath="_name" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" Width="90">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock
Text="{Binding _name}"
TextWrapping="Wrap" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>