【发布时间】:2016-10-13 13:59:01
【问题描述】:
我有一组两个级联的RadComboBoxes - 当一个被设置时,另一个填充。第二个组合框将其ItemSource 设置为CompositeCollection,该CompositeCollection 绑定到视图模型中的ObservableCollection。
我正在尝试将静态值添加到列表中。这个想法是 CompositeCollection 可以更改,但应该始终有一个名为 Other 的静态 ComboBoxItem 可用。
CustomerContact.cs:
public class CustomerContact
{
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
}
客户联系来源:
<CollectionViewSource x:Key="CustomerContactSource" Source="{Binding CustomerSite.CustomerContacts}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Name"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
其他客户联系人:
public CustomerContact OtherCustomerContactItem => new CustomerContact
{
Name = "Other",
Email = string.Empty,
PhoneNumber = string.Empty
};
Xaml 页面:
<telerik:RadComboBox ItemTemplate="{StaticResource ComboBoxItemTemplate}"
SelectedItem="{Binding CustomerContact}"
Text="{Binding Source=CustomerContact, Path=Name}">
<telerik:RadComboBox.ItemsSource>
<CompositeCollection>
<CollectionContainer Collection="{Binding Source={StaticResource CustomerContactSource}}"/>
<TextBlock Text="{Binding Source=OtherCustomerContactItem, Path=Name}"/>
</CompositeCollection>
</telerik:RadComboBox.ItemsSource>
</telerik:RadComboBox>
我不断收到一条错误消息,指出找不到 TextBlock 到 CustomerContact 的转换器。我究竟做错了什么? RadComboBox 有一个 ItemSource,它是 CustomerContact 的列表和一个单一的、不变的项目,也是类型为 CustomerContact。
任何帮助将不胜感激!!!
【问题讨论】:
-
发布您的视图模型代码.. 或您的 OtherCustomerContactItem 对象存在的位置.. 我认为它无法正确绑定 OtherCustomerContactItem。