![](/img/trans.png)
[英]How does ItemsControl.ItemsSource bind from something that doesn't implement IEnumerable?
[英]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.