如何在devexpress docklayoutmanager

时间:2015-06-29 11:19:46

标签: c# wpf devexpress code-behind devexpress-wpf

文件名SampleProject 我的xaml文件Mainwindow.xaml ----------

<Window x:Class="SampleProject.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxdo="http://schemas.devexpress.com/winfx/2008/xaml/docking" Closing="Window_Closing"
        Title="MainWindow" Height="800" Width="800" WindowState="Maximized">
    <Grid>
        <dxdo:DockLayoutManager x:Name="docklayoutmanager1" dxdo:RestoreLayoutOptions.RemoveOldPanels="False" dxdo:RestoreLayoutOptions.RemoveOldLayoutControlItems="False" Margin="0,50,0,0">
        </dxdo:DockLayoutManager>
        <Button Width="100" VerticalAlignment="Top" HorizontalAlignment="Center" Height="30" x:Name="ClickMe" Content="Click Me" Click="ClickMe_Click" Margin="323,10,369,729" />

    </Grid>
</Window>

` 我的xaml.cs文件MainWindow.xaml.cs -------------------

    using DevExpress.Xpf.Docking;
using DevExpress.Xpf.Layout.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SampleProject
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            if(File.Exists("test.xml"))
            {
                docklayoutmanager1.RestoreLayoutFromXml("test.xml");
            }
        }

        private void ClickMe_Click(object sender, RoutedEventArgs e)
        {
            var panel = docklayoutmanager1.DockController.AddPanel(DockType.None);
            panel.Caption = "Test Panel";
            panel.Name = "myPanel";
            panel.Content = "I want to serialize this code using guid Please provide example for creating such binding.";
            FloatGroup floatgroup = new FloatGroup();
            floatgroup.Name = "myFloatGroup";
            floatgroup.FloatSize = new Size(500,500);
            floatgroup.FloatLocation = new Point(300, 300);
            floatgroup.Add(panel);
            docklayoutmanager1.FloatGroups.Add(floatgroup);
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            string xmlFilePath = System.AppDomain.CurrentDomain.BaseDirectory + "test.xml";
            if (File.Exists("test.xml"))
            {
                docklayoutmanager1.SaveLayoutToXml("test.xml");
            }
            else
            {
                using (File.Create("test.xml")) { }
                docklayoutmanager1.SaveLayoutToXml("test.xml");
            }
        }
    }
}

我有一个文档布局管理器,以编程方式获取面板和控件,其中包含面板和控件。

保存时,我使用SaveLayoutToXml()为我的面板和使用bformatter.Serialize();的序列化控件实现此目的。

因为我有很多面板和独特的控件。我希望在保存和序列化之前将相同的控件放回到相同的面板中。请为我提供一个代码,以识别面板和控件的唯一ID。

我是否有任何可以指定GUID的整数id,因为BindableName不适用于它。

由于 DESH

2 个答案:

答案 0 :(得分:1)

以编程方式创建面板,并在运行时将它们添加到xaml文件中。

 UserC = new UserC();
            DocumentPanel dpanel = new DocumentPanel();
            dpanel.Name = "OpenUC" + count;
            dpanel.Caption = "Open User Control";
            dpanel.BindableName = "OpenUC" + count;
            var content = UserC;
            dpanel.Content = content;
            FloatGroup fGroup = new FloatGroup();
            fGroup.FloatSize = new Size(500, 500);
            fGroup.Items.Add(dpanel);

            DockLayoutManager1.FloatGroups.Add(fGroup);

答案 1 :(得分:0)

这是添加用户控件的方法,因为似乎没有人有兴趣帮助,我搜索并做了类似这样的事情:

 private FloatGroup CreateDocPanelFloatGroup(DocumentPanel dp)
        {
            FloatGroup floatGroup = new FloatGroup();
            floatGroup.FloatSize = new Size(500, 500);
            floatGroup.Items.Add(dp);

            return floatGroup;
        }

        private void OpenUC_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e)
        {         
            openUC = new OpenUC();
            DocumentPanel dp = new DocumentPanel();
            dp.Name = "OpenUC" + count;
            dp.Caption = "Open User Control";
            dp.BindableName = "OpenUC" + count;
            var content = openUC;
            dp.Content = content;
            DockLayoutManager1.FloatGroups.Add(CreateDocPanelFloatGroup(dp));          

        }