简体   繁体   中英

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 this.

    <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}" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM