Databinding with WPF User Control
I've been Googling for it; but without any luck. I think this is fairly simple.
I have a user control named TicketGroup
. TicketGroup
is the visual representation of a List object I have. The XAML code I've got looks like th开发者_运维问答is.
<c:TicketGroup Grid.Row="1" />
<c:TicketGroup Grid.Row="2" />
<c:TicketGroup Grid.Row="3" />
<c:TicketGroup Grid.Row="4" />
Inside the TicketGroup
I have an ItemsControl
called TicketItemsControl
and it has an ItemsSource =""
attribute in there. What I'm struggling to do is 'pass in' that ItemsSource
value in the above XAML.
Basically, the object I'm working with has four different lists. I want the first TicketGroup
to have an ItemsSource="{Binding Path=MyList1}"
and the second to have an ItemsSource="{Binding Path=MyList2}"
etc.... but I can't figure out how to do that.
You can set the datacontext of each c:TicketGroup to the List so you will have code like:
<c:TicketGroup Grid.Row="1" DataContext="{Binding Path=MyList1}" />
<c:TicketGroup Grid.Row="2" DataContext="{Binding Path=MyList2}" />
<c:TicketGroup Grid.Row="3" DataContext="{Binding Path=MyList3}" />
<c:TicketGroup Grid.Row="4" DataContext="{Binding Path=MyList4}" />
精彩评论