Results 1 to 4 of 4

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

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2012
    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
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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.

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    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 don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * 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??? *

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2012
    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
  •  



Click Here to Expand Forum to Full Width