How to Create WPF Docking Windows Using Code Only

在使用代码创建DotNetBar for WPF的停靠窗口时,要确保建立正确的父/子控件层级关系。正确的层级顺序为:DockSite -> SplitPanel -> DockWindowGroup -> DockWindow。例如,创建文档停靠窗口和右侧停靠窗口的代码分别给出。但你也可以使用DockSite.Dock快捷方法,只需传入DockWindow和停靠规格,控件会自动完成所有工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

When creating the DotNetBar for WPF docking windows from code make sure that you create proper parent/child hierarchy controls. The parent child relationship expected by the control is as follows:

DockSite
SplitPanel
DockWindowGroup
DockWindow

For example to create the document dock window you would use following code:

SplitPanel splitPanel = new SplitPanel();
DockWindowGroup dg = new DockWindowGroup();
DockWindow dw = new DockWindow();
dw.Header = "Document Window";
// Assign Dock Document content
dw.Content = myContent;
dg.Items.Add(dw);
splitPanel.Children.Add(dg);
MyDockSite.Content = splitPanel;
// Select the newly created dock window
dw.IsSelected = true;

To create an dockable window docked to the right you would use following code:

SplitPanel splitPanel = new SplitPanel();
DockWindowGroup dg = new DockWindowGroup();
DockWindow dw = new DockWindow();
dw.Header = "Dock Window";
// Assign Dock Window content
dw.Content = myContent;
dg.Items.Add(dw);
splitPanel.Children.Add(dg);
// Dock SplitPanel to the right side
DockSite.SetDock(splitPanel, Dock.Right);
// Set inital split panel size, since control is docked to the right number specified indicates width
DockSite.SetDockSize(splitPanel, 150);
MyDockSite.SplitPanels.Add(splitPanel);

However, note that you do not need to create complete structures in code. You can use shortcut method DockSite.Dock and pass in DockWindow as well as docking specification and control will perform all work for you.

Related posts:

  1. How To Start Using Wpf-Dock Control
  2. Docking Control support for Windows Forms or other windowed controls in DotNetBar for WPF
  3. Key Wpf-Dock DockWindow Properties, Events and Commands
  4. How to Create WPF Navigation Pane Items Using Code
  5. How to access WPF Dock Floating Window

Reference:http://www.devcomponents.com/kb2/?p=387

In .NET 6 and later versions, the `System.Windows.Forms` namespace is not included in the default installation of WPF applications. However, you can still use the `FolderBrowserDialog` class in your WPF application by adding a reference to the `System.Windows.Forms` NuGet package and using the `System.Windows.Forms.Integration` namespace. Here are the steps to use `FolderBrowserDialog` in .NET 6 WPF: 1. Add a reference to the `System.Windows.Forms` NuGet package in your WPF project. 2. Add the following using statements to the top of your code file: ```csharp using System.Windows.Forms; using System.Windows.Forms.Integration; ``` 3. In your code, create a `FolderBrowserDialog` object and use the `ShowDialog` method to display the dialog box: ```csharp FolderBrowserDialog dialog = new FolderBrowserDialog(); if (dialog.ShowDialog() == DialogResult.OK) { // do something with the selected folder } ``` 4. If you want to use the `FolderBrowserDialog` in a WPF window or page, you can use the `WindowsFormsHost` control to host the dialog box: ```xml <Window xmlns:winforms="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" xmlns:forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" ...> <Grid> <winforms:WindowsFormsHost> <forms:FolderBrowserDialog x:Name="folderDialog" /> </winforms:WindowsFormsHost> </Grid> </Window> ``` Then, you can use the `ShowDialog` method to display the dialog box: ```csharp if (folderDialog.ShowDialog() == DialogResult.OK) { // do something with the selected folder } ``` Note that you will also need to add a reference to the `WindowsFormsIntegration` assembly in your WPF project.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值