Reputation: 56
Hey everyone, I'm working on a project that is a C# WPF desktop app to create and edit a complex system. Simply think of it as and editor that can put together a full description of a car with all it's subcomponents. I want each different component of the car to have a separate editor window. Like select the painting on the car and tada a sidewindow appears where you can fully customize the car's paint. Then when you click on the engine, that same sidewindow get's replaced by a new editor about the car's engine.
How can I make that editor window that I already created with xaml and codebehind to appear as a part of the MainWindow, embedded as a sidebar? If possible, I would avoid any 3rd party libraries, but if there is no other 'clean' way of doing it then I'm open to suggestions in that area as well.
I have fully functional windows that I created with the designer, wrote all the code for it to work, now I just have to find a way to embed those into the MainWindow on a press of a button.
Thanks for any answers
Upvotes: 1
Views: 774
Reputation: 169280
If you want something to "part of the MainWindow", you should not create another window because a Window
cannot be a child of another element.
What you probably want to do is to move the XAML markup and code-behind from your current subwindow into a UserControl. You can then put the UserControl
(s) into an appropriate Panel in your MainWindow
.
For example, if you want UserControl
to appear a sidebar in the window, you could use a DockPanel
to dock it to the right:
<DockPanel>
<Border DockPanel.Dock="Right" Background="Yellow">
<local:SidebarUserControl Margin="10" />
</Border>
<TextBlock>main content...</TextBlock>
</DockPanel>
Upvotes: 1