ComboBox TextWrap Binding

蹲街弑〆低调 提交于 2019-12-04 04:21:33

问题


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:


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>


来源:https://stackoverflow.com/questions/18825882/combobox-textwrap-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!