Results 1 to 4 of 4

Thread: Adding a custom control to a stackpanel from another class

  1. #1
    New Member
    Join Date
    Aug 12
    Posts
    2

    Question 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!

  2. #2
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 99
    Location
    Sweden
    Posts
    13,533

    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.
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,791

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

  4. #4
    New Member
    Join Date
    Aug 12
    Posts
    2

    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
  •