[英]How to display a different value for dropdown list and selected item in a CheckComboBox in Xceed WPF toolkit?
I've got a CheckComboBox bound to a list consisting of one simple index and a full description like this: 我有一个CheckComboBox绑定到一个列表,该列表由一个简单的索引和完整的说明组成,如下所示:
code full_description
1 Bus
2 Car
3 Motobike
Is it possible to show just 1,2,3 for selected items and show full description when dropping down the list? 下拉列表时是否可以仅显示1,2,3并显示完整说明? I found a similar question here .
我在这里发现了类似的问题。 But since CheckComboBox using the difference implementation, I have modified the part of
class ComboBoxItemTemplateSelector
as follows: 但是由于CheckComboBox使用差异实现,因此我对
class ComboBoxItemTemplateSelector
的部分进行了如下修改:
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
SelectorItem selectorItem = VisualTreeHelpers.GetVisualParent<SelectorItem>(container);
if (selectorItem != null)
{
return DropDownTemplate;
}
return SelectedTemplate;
}
It works fine with dropdown list, but no luck with selected items. 它在下拉列表中正常工作,但对选定项没有运气。 I tried to dig into the source code of CheckComboBox but got nothing.
我试图深入研究CheckComboBox的源代码,但一无所获。 Hope someone can help me out.
希望有人可以帮助我。 Thanks.
谢谢。
Did you try to just set the ContentTemplate
of ItemContainerStyle
? 您是否尝试仅设置
ItemContainerStyle
的ContentTemplate
?
<ComboBox.ItemContainerStyle>
<!--Not sure what TargetType you should use-->
<Style TargetType="ComboBoxItem">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<!--Here goes your DropDownTemplate-->
<TextBlock Text="{Binding Description}" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ComboBox.ItemContainerStyle>
Also, set DisplayMemberPath
to your desired property. 另外,将
DisplayMemberPath
设置为所需的属性。
1.override ToString()
in your item class: 1.override
ToString()
在您的项目类:
public override string ToString()
{
return full_description;
}
2.set DisplayMemberPath
to code
2.设置
DisplayMemberPath
为code
<CheckComboBox ItemsSource="{Binding CarList}"
DisplayMemberPath="code" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.