Click here to Skip to main content
15,883,990 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Learning the ropes of WPF data binding.. What's wrong with the following simple binding?
I have a window with some instances of a user control:
<usercontrol mode="hold" x:class="MyUserCtrl" x:name="CommandRow" xmlns:x="#unknown" /><usercontrol.resources>
  <datatemplate x:key="MyItemListTemplate" xmlns:x="#unknown">
     <stackpanel orientation="Horizontal">
       <Label Content="{Binding Path=ItemName}" />                
       <textbox text="{Binding Path=ItemValue}" />
     </stackpanel>
   </datatemplate>
</usercontrol.resources>
<listbox name="ListBoxParams">
                ItemsSource="{Binding ElementName=CommandRow, Path=_MyItems}"
                ItemTemplate="{StaticResource MyItemListTemplate}" />
</listbox>

and in the code behind the user control has
List<MyItem> _MyItems
Posted
Updated 11-Oct-11 0:12am
v3

1 solution

Hi,

You need to have a datacontext set properly - unfortunately your code examples have become a little bit garbled, is there any chance you can update the question with a bit more code?

We need to see what the CommandRow object is.

In essence you should have a viewmodel class that contains your commands, the CommandRow should bind to that and so should the list box params - you should try and avoid binding one UI element list source to another, it looks like it shouldn't be needed in this case.

Can I suggest my article on getting started with WPF?


[Getting Started with WPF^]

This explains binding to a list in detail - if you do have to do it the way it appears you are doing it, we're going to need better code samples!

Let me know if I can do anything else to help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900