Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Application in C# winform
Wpf element hosted in usercontrol. I want to set label on parent form on which wpf element is hosted. I tried through constructor but is not possible yet. I also made properties for this label and accessed in wpf code but not possible.
Please anyone suggest me proper solution.
on Parent form(CHDatabaseManagement) Code for constructor is
C#
public CHDatabaseManagement(string Displaylbl)
      {
          InitializeComponent();
          DisplayLabel.Text = Displaylbl;
      }



------
and on wpf form code is
CHDatabaseManagement chdab = new CHDatabaseManagement("");
but when compile then label shows default text value
Posted
Updated 13-Dec-13 1:50am
v3
Comments
Maciej Los 13-Dec-13 7:34am    
We need more details (code).
sp_suresh 13-Dec-13 7:50am    
please see code has given

1 solution

Wrong approach entirely. A child control should never try to change a control in a parent container. It's concern is with itself and itself alone.

If there is data that needs to be sent back up the chain, use an event to do it. The paren container or form should decide what to do with the data, not the child controls.
 
Share this answer
 
Comments
sp_suresh 14-Dec-13 3:22am    
thanks for reply..I understand that child control never try to change control but our requirement is that it should change.
can u please give idea for that how can i achieve this?...
Dave Kreskowiak 14-Dec-13 9:30am    
Wrong. That's not a real "requirement". What you're describing is the extremely naïve way of getting what you want.

Do it the CORRECT way and you won't screw yourself into a corner. A control should have absolutely no knowledge of the container it's used it or the form it's on, PERIOD. The way you want to do it locks your control into being used on that form ONLY and no other. Professional developers NEVER do this!

Use an event to pass the data back up the container chain and you have much greater flexibility to use the control not only on other forms, but in an depth of containers.

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