标题说了这一切但我们说我有一个接口IPerson
而IPerson
有UserControl作为其属性。
在主xaml中,我已经有了一个Observable集合,类型为IPerson的人,我将ItemsSource绑定到人ItemsSource={Binding People}
如何在ItemsControl中显示与IPerson关联的UserControl?
接口
public interface IPerson
{
string DisplayName { get; }
/// <summary>
/// Call that is going to add the UI component to XML Editor
/// </summary>
UserControl DisplayingUserControl { get; }
}
in vm
public ObservableCollection<IPerson> People
在视图
上 <ItemsControl ItemsSource="{Binding People}" Padding="3">
<ItemsControl.ItemTemplate>
<DataTemplate>
<XXX Content="{Binding DisplayingUserControl}" Height="Auto" Width="Auto"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
我想知道如何填写XXX
答案 0 :(得分:1)
假设您在IPerson界面中拥有属性UC,您可以显示UserControl,如:
<ItemsControl x:Name="IC">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Label Content="{Binding UC}" Height="Auto" Width="Auto"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>