【发布时间】:2011-04-16 10:26:08
【问题描述】:
我正在对列表框的ItemSource 进行数据模板化以显示一系列组合框。我想将组合的DisplayMemberPath 提供给一个属性,该属性与它自己的ItemsSource 的来源不同。 (假设DisplayMemberPath 只是一个代表属性名称的字符串,我从用户那里得到这个)。我通过CollectionViewSource 实现了这一点,但所有组合框都显示相同的列表。
我期望在数据模板化之后显示组合框,
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
}
【问题讨论】:
标签: wpf xaml wpf-controls binding