You can define a Window, Page or UserControl in external XAML files and then, with DXDocking, load their contents into DocumentPanel objects.
This example demonstrates how to load an external Window and UserControl into DocumentPanels.
In the example three approaches are demonstrated:
1) The contents of MyWindow.xaml is loaded into a DocumentPanel at design time (in XAML) via the DocumentPanel.Content property. The Content property accepts a Uri object, which must refer to a XAML file defining a Window, Page or UserControl.
[XAML]<dxdo:DocumentPanelx:Name="docPanel2"Caption="Panel 2"Content="{dxdo:RelativeUri UriString=CustomWindows\\MyWindow.xaml}"/>
2) The DocumentPanel.Content property is set with a Uri object at runtime:
[C#]docPanel1.Content=newUri(@"CustomWindows\MyWindow1.xaml",UriKind.Relative);
3) The DockLayoutManager.DockController.AddDocumentPanel method creates a new DocumentPanel object and loads the contents of an external XAML file into the created panel.
[C#]panel1=dockLayoutManager1.DockController.AddDocumentPanel(documentGroup1,newUri(@"CustomWindows\UserControl1.xaml",UriKind.Relative));panel1.Caption="Document "+(ctr++).ToString();
In the example, the XAML file defines a UserControl object. The loaded UserControl is accessed via the DocumentPanel's Control property and then a method on the UserControl is invoked.
[C#]//...(panel1.ControlasUserControl1).SetDataContext(imageInfo);
You can see this in action by clicking the "Set DataContext for UserControl" button in the example.
Question Comments
Added By: Sudha Raman at: 10/22/2013 9:21:47 AM
Hi,
I am following the same approach in my project. My question is how to close the Usercontrol from Button click event of it.(not using the 'X' on right corner- usercontrol unloaded event).
Thanks
Sudha.
Hi,
If you have a button within a UserControl displayed within a DocumentPanel, you can use the Button.Click event to close the current DocumentPanel:
private void button1_Click(object sender, RoutedEventArgs e) {
DockLayoutManager dm = DockLayoutManager.GetDockLayoutManager(this);
dm.DockController.Close(dm.ActiveDockItem);
}
Thanks, Alex.
Hi,
I've a windows (MDI) with buttons (save, new ecc.) and document panel with loaded windows at runtime. I need to send commands from child windows to MDI window (enable/disable buttons). How can I do?
Thanks, Andrea.