簡體   English   中英

如何將ItemsControl的ItemsSource綁定到IEnumerable的T類內部的屬性 <T> ?

[英]How to bind ItemsControl's ItemsSource to a Property that is inside of class T from IEnumerable<T>?

標題說明了一切,但可以說我有一個IPerson接口,而IPerson具有UserControl作為其屬性。

在主要的xaml中,我已經有一個IPerson類型的Observable集合People,並且我已將ItemsSource與People綁定了ItemsItem 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM