Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am new to WPF .... I have created Five buttons present in Main Window in WPF , created five usercontrol , want to call each usercontrol for each respective button.. plz help .. already tried below code .. bt not displaying the usercontrol.. tho the WPF main form execute without any error.

C#
IssueTripSheet i = new IssueTripSheet();
//new IssueTripSheet().Loaded(i);
Grid2.Children.Clear();//Clearing Child Elements in Grid Panel
Grid2.Children.Add(i);
Posted
Updated 28-Feb-14 5:48am
v2
Comments
Sergey Alexandrovich Kryukov 28-Feb-14 9:58am    
There is no such concept, "call a control". What exactly is your problem?
—SA
Saiprasad007 28-Feb-14 23:16pm    
call usercontrol ... i mean button click on main window .... which will place usercontrol on the grid panel of main window.
Sergey Alexandrovich Kryukov 28-Feb-14 23:59pm    
It all depends on the IssueTripSheet type. If this is just some arbitrary type, you won't see anything good in the grid. You can implement appropriate properties, IPropertyChanged, add binding to the grid view data template... did you care about all that? If not, what would you expect?
—SA
Saiprasad007 1-Mar-14 3:06am    
without any binding, cant i directly place Usercontrol1 created by me onto Grid panel of main window with a single button click from main window... ??
Sergey Alexandrovich Kryukov 1-Mar-14 13:26pm    
Not sure. You need somehow to tell each cell where to get data from. How are you going to specify that? The intended property for doing so is the data template with binding to some data. Even if such approach existed, it still would be some kind of binding, but crafted by you. Can you see the point?
—SA

1 solution

Please see my comment to the question. No matter what you do, it still would be some kind of binding. You can either bind the control directly to your class representing your items (IssueTripSheet), and then you would need to implement this class properly, to make in "bindable". This approach is explained in my recent asnwer:
Binding arbitary class to a wpf datagrid[^].

Alternatively, you can virtualize the binding, and then you can write mapping code between a control and your data the way you want, using some binding code. This approach, in application to a grid view, is explained in this article: WPF: Data Virtualization[^].

I would suggest that you first learn the intended ways of using WPF controls, understand them well, and then try to think what else you can do with them. I understand: you probably want to find an "easy" way, which does not need learning the concepts WPF designer try to push on you. This is quite explainable. But, in many cases, moving against the main stream, the "easy way" can turn the longest one. And the main stream is binding prescribed in XAML. :-)

Good luck,
—SA
 
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