如何将 ItemsControl 的 ItemsSource 绑定到来自 IEnumerable<T> 的 class T 内部的 属性?
How to bind ItemsControl's ItemsSource to a Property that is inside of class T from IEnumerable<T>?
标题说明了一切,但可以说我有一个界面 IPerson
并且 IPerson
有 UserControl 作为它的 属性。
在主体中 xaml 我已经有一个 Observable collection IPerson 类型的人并且我已经将 ItemsSource 与 People 绑定 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; }
}
在虚拟机中
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
假设您在 IPerson 界面中有一个 属性 UC,您可以像这样显示 UserControl:
<ItemsControl x:Name="IC">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Label Content="{Binding UC}" Height="Auto" Width="Auto"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
标题说明了一切,但可以说我有一个界面 IPerson
并且 IPerson
有 UserControl 作为它的 属性。
在主体中 xaml 我已经有一个 Observable collection IPerson 类型的人并且我已经将 ItemsSource 与 People 绑定 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; }
}
在虚拟机中
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
假设您在 IPerson 界面中有一个 属性 UC,您可以像这样显示 UserControl:
<ItemsControl x:Name="IC">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Label Content="{Binding UC}" Height="Auto" Width="Auto"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>