我是DataTemplating的列表框的ItemSource
以显示一系列组合框。我想将组合的DisplayMemberPath
赋予一个属性,该属性与它自己的ItemsSource
不同。 (假设DisplayMemberPath
只是一个表示属性名称的字符串,我从用户那里得到这个)。我用CollectionViewSource
实现了这一点,但所有组合框都显示相同的列表。WPF DataTemplate和绑定 - 这可能在XAML?
什么我期待着有后的数据模板是有组合框显示,
ComboboxInstance1.DisplayMemberPath = PropertyMapOfEmployee in FilterControls[0]
ComboboxInstance2.DisplayMemberPath = PropertyMapOfEmployee in FilterControls[1]
这是可能在XAML实现?
谢谢。玛尼
用户控件:
<Resources>
<CollectionViewSource x:Key="bindingSource" Source="{Binding BindingItems}"/>
<CollectionViewSource x:Key="FilterSource" Source="{Binding FilterControls}"/>
<DataTemplate DataType="{x:Type CustomTypes:FilterElement}">
<ComboBox ItemsSource="{Binding Source={StaticResource bindingEmp}"
DisplayMemberPath="{Binding Source={StaticResource FilterSource},
Path=PropertyMapofEmployee}" />
</DataTemplate>
<Resources>
---
<DockPanel>
<ListBox x:Name="lstBox" ItemsSource="{Binding FilterControls}" />
</DockPanel>
视图模型:
List<FilterElement> FilterControls;
List<Employee> Employees
class FilterElement
{
string Caption;
String PropertyMapofEmployee
}
我不认为PropertyMapOfEmployee是Employee类的一个属性,所以我不认为这会起作用。 – 2010-09-23 18:49:47
谢谢..这实际上修复了原来的和当前的问题。 – 2010-09-23 18:53:52
它工作原理是因为PropertyMapOfEmployee是FilterControls的一个特性,它绑定到ListBox(数据模型)。因此,组合绑定总是指父级,除非在绑定中使用'Source ='专门设置。因此它起作用。 – 2010-09-23 18:56:04