ComboBox TextWrap Binding

2020-04-11 19:42发布

I have the following 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"/>

I wish to apply Text Wrapping to this combobox and followed to code snippet from the answer 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>

But this template is breaking the binding and the combobox displays no values. Any help would be appreciated

1条回答
劫难
2楼-- · 2020-04-11 20:37

Figured it out

<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>
查看更多
登录 后发表回答