组合框 TextWrap 绑定 [英] ComboBox TextWrap Binding

查看:34
本文介绍了组合框 TextWrap 绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下组合框

<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 应用到这个组合框并遵循答案中的代码片段 这里

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

推荐答案

想通了

<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>

这篇关于组合框 TextWrap 绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆