Exemple #1
0
        private IEnumerable <SerializedLayout> GetChildren(IEnumerable <XElement> elements)
        {
            var children = elements.Where(x => x.Elements().Any(y => y.GetAttribute("name") == "ParentName" && y.Value == this.Name));

            return(children
                   .Select(child =>
            {
                var width = child.GetAttribute("ItemWidth");
                var height = child.GetAttribute("ItemHeight");
                var name = child.GetAttribute("Name");
                var type = child.GetAttribute("TypeName");
                var orientation = child.GetAttribute("Orientation");
                var isActive = child.GetAttribute("IsActive");

                var layout = new SerializedLayout(name, orientation, elements)
                {
                    Width = width == null || width == "*" ? 0.0 : double.Parse(width.Replace("*", ""), CultureInfo.InvariantCulture),
                    Height = height == null || height == "*" ? 0.0 : double.Parse(height.Replace("*", ""), CultureInfo.InvariantCulture),
                    Parent = this.Name,
                    IsActive = isActive == null ? false : Boolean.Parse(isActive),
                    LayoutType = type
                };

                return layout;
            }));
        }
        public SerializedLayout ToSerializedLayout()
        {
            if (null == DockingLayout)
            {
                return(null);
            }

            var file = Path.GetTempFileName();

            using (var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write))
            {
                var memoryStrema = new MemoryStream(DockingLayout);
                memoryStrema.CopyTo(fileStream);
            }

            var xmlLayout        = XElement.Load(file);
            var elements         = xmlLayout.XPathSelectElement("//*[@name='Items']").Elements();
            var serializedLayout = SerializedLayout.Create(elements);

            if (null != Widgets)
            {
                foreach (var widget in Widgets)
                {
                    var target = serializedLayout.FindByName(widget.ParentName);

                    //hidden widgets
                    if (null == target)
                    {
                        continue;
                    }

                    target.Widget = new SerializedWidget()
                    {
                        Id = widget.ViewModelId,
                        SerializedGridLayouts = widget.GridsLayout.Any() ? widget.GridsLayout.Select(y => SerializedGridLayout.GetLayout(y.Layout)).ToList() : null
                    };
                }
            }

            return(serializedLayout);
        }