Click here to Skip to main content
15,746,110 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello everyone,

I am making one student registration system in WPF, i have one very odd query regarding it that i have one window inside which there are two stackpanels and in both the stack panels usercontrol are added dynamically.
Eg.Usercontrol 1 is added to Stackpanel1 for Window now these usercontrol-1 are generated dynamically lets say they are student names , now when i click one of the student names (usercontrol -1) it should get all the details of that particular student and call new usercontrol-2 and add as a child to stackpanel-2 in the window.

I am able to handle the click event for usercontrol-1 for each and every student and also get their information and pass those information to usercontrol-2 now what i need is how do i add that usercontrol -2 to stackpanel-2 of window from by writing code inside usercontrol-1 OR is there any other method for doing the same.

Please help me regarding this , i am really stucked up !!

Thanks & regards,
Krunal Panchal
Posted
Comments
Sergey Alexandrovich Kryukov 27-Mar-12 12:45pm    
Not clear how it can be a problem. This is your user control; you can do whatever you want with it.
--SA

1 solution

If you used WPF right you would use MVVM, and use ListBox's. A list box can have different types of containers (stackpanel, etc) with the ItemContainerStyle. You fill the ListBox by binding to the ItemsSource property. You can respond to changes in the selected item in the ListBox by binding to the SelectedItem property. When this property changes, you can do whatever is needed in responce. The other thing you need to know is that you will want to use the ObservableCollection to store the lists since this class automatically handles firing the PropertyChanged events. Binding can be done to a more complex paths such as {binding SelectedItem.SomeList}. Also have to set the DataContextt for the form/usercontorl to the class containing the properties.

If you are using WPF, you really need to learn about the MVVM pattern and how to use this with WPF. Much easier once you understand it. Do a search on the pattern. Here is one link on codeproject: Model-View-ViewModel (MVVM) Explained[^]
 
Share this answer
 
v2

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