简体   繁体   中英

How To add a ChildWindow to MainWindow in WPF ,programatically?

I have a child window of type:

Xceed.Wpf.Toolkit.ChildWindow

and my main window is of type System.Windows.Window How can I programmatically all my child window into my Main window?

I found the solution: in your xaml of main window:

<Window x:Class="WpfApplicationTestChildWindow.Window2"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplicationTestChildWindow"
        xmlns:xceed="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
        xmlns:primitive="clr-namespace:Xceed.Wpf.Toolkit.Primitives;assembly=Xceed.Wpf.Toolkit"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <primitive:WindowContainer Name="cntr1">
        </primitive:WindowContainer>
    </Grid>
</Window>

and in the code behind:

using System.Windows;
namespace WpfApplicationTestChildWindow
{
    public partial class Window2 : Window
    {
        public Window2()
        {
            InitializeComponent();
            ChildWindow1 child1 = new ChildWindow1();
            cntr1.Children.Add(child1);
            child1.Show();
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM