有人知道如何将ObservableCollection对象的集合链接到OwnUserControl吗?OwnUser控件集成在WPF应用程序的DataTemplate中?我已经尝试了几个绑定路径(在WPF代码中,绑定路径=MAIN-QUESTION),但我不起作用。所以我想也许我对这个概念有一个基本的误解。
ViewModel:
public class MyViewModel
{
private ObservableCollection<object> _timeLineCollection = new ObservableCollection<object>();
public ObservableCollection<object> TimeLineCollection
{
get { return _timeLineCollection; }
set { _timeLineCollection = value; }
}
}
WPF-
<ItemsControl Name="ItemsControlOverview" ItemsSource="{Binding TimeLineCollection}">
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type viewModel:TimeLineTicketViewModel}">
<localtemplates:TimeLineTicket DataContext="{Binding Path=MAIN-QUESTION}" x:Name="TimeLineTicket"/>
</DataTemplate>
</ItemsControl.Resources>
</ItemsControl>
谢谢你的帮助!
问候坐鸭
尝试更改ItemsControl的ItemTemplate属性,而不是Resource。项目模板
<ItemsControl Name="ItemsControlOverview" ItemsSource="{Binding TimeLineCollection}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type viewModel:TimeLineTicketViewModel}">
<localtemplates:TimeLineTicket DataContext="{Binding Path=MAIN-QUESTION}" x:Name="TimeLineTicket"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
问题解决了,我忘记初始化用户控件。非常业余的失败。
对的混乱深表歉意
问候