locked
Passing WPF control at runtime to a Windows form hosted WPF control RRS feed

  • Question

  • We need to pass a WPF control at run time to another WPF control which is hosted in a Windows Form environment. We are able to achieve host WPF control control in Windows Forms. Dynamic addition of another WPF control to WinForm hosted WPF control, we are seeking help.

    Thank you,

    Aneesh

    Tuesday, February 15, 2011 11:57 AM

Answers

  • Hi Aryam,

    I think you want to add a WPF control to another WPF control, based on my experience, I think it is nothing to do with the control is hosted in WinForm, for example, if your control is a ContentControl, you could just set the another control's content property, like below:

        public partial class MainWindow : Window

        {

            Image OriginalControl = new Image();

            Button AnotherControl = new Button();

            public MainWindow()

            {

                InitializeComponent();

                OriginalControl.Source = new BitmapImage(new Uri(@"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg", UriKind.RelativeOrAbsolute));

                this.AnotherControl.Content = OriginalControl;

                this.Content = AnotherControl;

            }

           

        }

    Follow this direction, I think you could complete that pass a control to another control.

    If I have misunderstood your concern, please let me know.

     

    Best regards,


    Sheldon _Xiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Sheldon _Xiao Wednesday, February 23, 2011 10:05 AM
    Friday, February 18, 2011 5:33 AM

All replies

  • Hi Aryam,

    I think you want to add a WPF control to another WPF control, based on my experience, I think it is nothing to do with the control is hosted in WinForm, for example, if your control is a ContentControl, you could just set the another control's content property, like below:

        public partial class MainWindow : Window

        {

            Image OriginalControl = new Image();

            Button AnotherControl = new Button();

            public MainWindow()

            {

                InitializeComponent();

                OriginalControl.Source = new BitmapImage(new Uri(@"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg", UriKind.RelativeOrAbsolute));

                this.AnotherControl.Content = OriginalControl;

                this.Content = AnotherControl;

            }

           

        }

    Follow this direction, I think you could complete that pass a control to another control.

    If I have misunderstood your concern, please let me know.

     

    Best regards,


    Sheldon _Xiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Sheldon _Xiao Wednesday, February 23, 2011 10:05 AM
    Friday, February 18, 2011 5:33 AM
  • Hi Aryam,

    I am marking your issue as "Answered", if you have new findings about your issue, please unmark.

     

    Best regards,


    Sheldon _Xiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, February 23, 2011 10:04 AM