一、演示概述
此演示展示了如何通过RadDocking控件自身所提供的SaveLayout()保存布局信息,以及通过LoadLayout()方法来加载布局信息。如此一来,就可以将用户自定义的布局信息持久化保存到文件中,当用户再次打开应用时,可将布局完好如初的恢复显示。
相关下载(屏幕录像):http://pan.baidu.com/s/1gd6DwDt
在线播放:http://v.youku.com/v_show/id_XODcyNjE0Mjg4.html
温馨提示:如果屏幕录像和代码不能正常下载,可站内留言,或发邮件到[email protected]
二、运行效果
效果如下图所示:
三、关键代码
1、保存布局的代码
/// <summary> /// 将RadDocking的布局信息转换为字符串。 /// </summary> /// <returns></returns> private string SaveLayoutAsString() { MemoryStream stream = new MemoryStream(); this.RadDocking.SaveLayout(stream); stream.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(stream); return reader.ReadToEnd(); }
2、加载布局的代码
/// <summary> /// 从字符串中加载RadDocking的布局信息。 /// </summary> /// <param name="xml"></param> private void LoadLayoutFromString(string xml) { using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml))) { stream.Seek(0, SeekOrigin.Begin); this.RadDocking.LoadLayout(stream); } }
3、持久化生成的XML
RadDocking的布局持久化生成的字符串,也即为一个XML,内容大致如下所示:
<?xml version="1.0" encoding="utf-8"?> <RadDocking> <DocumentHost> <RadSplitContainer> <Items> <RadPaneGroup SelectedIndex="0"> <Items> <RadPane SerializationTag="LayoutXml" IsDockable="True" Header="Layout Xml" /> <RadDocumentPane SerializationTag="DocumentPane" IsDockable="True" Title="Document 1" Header="Document 1" /> </Items> </RadPaneGroup> </Items> </RadSplitContainer> </DocumentHost> <SplitContainers> <RadSplitContainer Dock="DockedLeft" Width="240"> <Items> <RadPaneGroup SelectedIndex="0"> <Items> <RadPane SerializationTag="PaneLeft1" IsDockable="True" Header="Pane Left 1" /> <RadPane SerializationTag="PaneLeft2" IsDockable="True" Header="Pane Left 2" /> <RadPane SerializationTag="PaneLeft3" IsDockable="True" Header="Pane Left 3" /> <RadPane SerializationTag="PaneLeft4" IsDockable="True" Header="Pane Left 4" /> </Items> </RadPaneGroup> </Items> </RadSplitContainer> <RadSplitContainer Dock="DockedRight" Width="240"> <Items> <RadPaneGroup SelectedIndex="0"> <Items> <RadPane SerializationTag="PaneRight1" IsDockable="True" Header="Pane Right 1" /> </Items> </RadPaneGroup> </Items> </RadSplitContainer> <RadSplitContainer Dock="DockedTop" Height="180"> <Items> <RadPaneGroup SelectedIndex="0"> <Items> <RadPane SerializationTag="PaneTop1" IsDockable="True" Header="Pane Top 1" /> </Items> </RadPaneGroup> </Items> </RadSplitContainer> </SplitContainers> </RadDocking>
四、相关资源
1、Telerik官方帮助文档地址:http://docs.telerik.com/devtools/wpf/controls/raddocking/overview2
时间: 2024-11-04 14:47:05