|
-
Aug 13th, 2012, 08:58 PM
#1
Thread Starter
New Member
Adding a custom control to a stackpanel from another class
I have a window with a stackpanel named stackpanel and I have added some custom controls to it in xaml which works great.
Now my program dynamically creates some user controls (with buttons) inside the stackpanel. I want to be able to click a button inside my user control and dynamically add another control to the stackpanel.
I can't seem to get this to work since it is in a different class. How can I add a control to the stackpanel from another control? I couldn't figure out how to use directcast either.
Thank you!
-
Aug 13th, 2012, 09:44 PM
#2
Re: Adding a custom control to a stackpanel from another class
Moved to the WPF forum.
Letting the user control itself dynamically add another control to its parent container is a bit strange behaviour since it limits the use of the control. So what you probably should do is to let your user control raise an event when you click on the button and handle it from that event.
-
Aug 13th, 2012, 09:47 PM
#3
Re: Adding a custom control to a stackpanel from another class
you don't... ideally, you would raise an event... which would then be handled by the parent container (the app) to add what is needed. The control shouldn't care if it's in a stack panel or not...
-tg
-
Aug 14th, 2012, 07:31 PM
#4
Thread Starter
New Member
Re: Adding a custom control to a stackpanel from another class
Thanks, I got it to work!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|