コード例 #1
0
        public DesignItem RegisterComponentForDesignerRecursiveUsingXaml(object component)
        {
            string componentXaml = XamlWriter.Save(component);
            var    xamlObject    = XamlParser.ParseSnippet(((XamlDesignItem)_context.RootItem).XamlObject, componentXaml, ((XamlDesignContext)_context.RootItem.Context).ParserSettings);

            return(RegisterXamlComponentRecursive(xamlObject));
        }
コード例 #2
0
        void Click_EditStyle(object sender, RoutedEventArgs e)
        {
            var    element         = designItem.View;
            object defaultStyleKey = element.GetValue(FrameworkElement.DefaultStyleKeyProperty);
            Style  style           = Application.Current.TryFindResource(defaultStyleKey) as Style;

            var service = ((XamlComponentService)designItem.Services.Component);

            var           ms     = new MemoryStream();
            XmlTextWriter writer = new XmlTextWriter(ms, System.Text.Encoding.UTF8);

            writer.Formatting = Formatting.Indented;
            XamlWriter.Save(style, writer);

            var rootItem = this.designItem.Context.RootItem as XamlDesignItem;

            ms.Position = 0;
            var sr   = new StreamReader(ms);
            var xaml = sr.ReadToEnd();

            var xamlObject = XamlParser.ParseSnippet(rootItem.XamlObject, xaml, ((XamlDesignContext)this.designItem.Context).ParserSettings);

            var styleDesignItem = service.RegisterXamlComponentRecursive(xamlObject);

            designItem.Properties.GetProperty("Resources").CollectionElements.Add(styleDesignItem);
        }
コード例 #3
0
        public override DesignItem Clone()
        {
            DesignItem     item     = null;
            var            xaml     = XamlStaticTools.GetXaml(this.XamlObject);
            XamlDesignItem rootItem = Context.RootItem as XamlDesignItem;
            var            obj      = XamlParser.ParseSnippet(rootItem.XamlObject, xaml, ((XamlDesignContext)Context).ParserSettings);

            if (obj != null)
            {
                item = ((XamlDesignContext)Context)._componentService.RegisterXamlComponentRecursive(obj);
            }
            return(item);
        }
コード例 #4
0
        /// <summary>
        /// Paste items from clipboard into the designer.
        /// </summary>
        public void Paste()
        {
            bool   pasted              = false;
            string combinedXaml        = Clipboard.GetText(TextDataFormat.Xaml);
            IEnumerable <string> xamls = combinedXaml.Split(_delimeter);

            xamls = xamls.Where(xaml => xaml != "");

            DesignItem parent = _context.Services.Selection.PrimarySelection;
            DesignItem child  = _context.Services.Selection.PrimarySelection;

            XamlDesignItem rootItem    = _context.RootItem as XamlDesignItem;
            var            pastedItems = new Collection <DesignItem>();

            foreach (var xaml in xamls)
            {
                var obj = XamlParser.ParseSnippet(rootItem.XamlObject, xaml, _settings);
                if (obj != null)
                {
                    DesignItem item = _context._componentService.RegisterXamlComponentRecursive(obj);
                    if (item != null)
                    {
                        pastedItems.Add(item);
                    }
                }
            }

            if (pastedItems.Count != 0)
            {
                var changeGroup = _context.OpenGroup("Paste " + pastedItems.Count + " elements", pastedItems);
                while (parent != null && pasted == false)
                {
                    if (parent.ContentProperty != null)
                    {
                        if (parent.ContentProperty.IsCollection)
                        {
                            if (CollectionSupport.CanCollectionAdd(parent.ContentProperty.ReturnType, pastedItems.Select(item => item.Component)) && parent.GetBehavior <IPlacementBehavior>() != null)
                            {
                                AddInParent(parent, pastedItems);
                                pasted = true;
                            }
                        }
                        else if (pastedItems.Count == 1 && parent.ContentProperty.Value == null && parent.ContentProperty.ValueOnInstance == null && parent.View is ContentControl)
                        {
                            AddInParent(parent, pastedItems);
                            pasted = true;
                        }
                        if (!pasted)
                        {
                            parent = parent.Parent;
                        }
                    }
                    else
                    {
                        parent = parent.Parent;
                    }
                }

                while (pasted == false)
                {
                    if (child.ContentProperty != null)
                    {
                        if (child.ContentProperty.IsCollection)
                        {
                            foreach (var col in child.ContentProperty.CollectionElements)
                            {
                                if (col.ContentProperty != null && col.ContentProperty.IsCollection)
                                {
                                    if (CollectionSupport.CanCollectionAdd(col.ContentProperty.ReturnType, pastedItems.Select(item => item.Component)))
                                    {
                                        pasted = true;
                                    }
                                }
                            }
                            break;
                        }
                        else if (child.ContentProperty.Value != null)
                        {
                            child = child.ContentProperty.Value;
                        }
                        else if (pastedItems.Count == 1)
                        {
                            child.ContentProperty.SetValue(pastedItems.First().Component);
                            pasted = true;
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                foreach (var pastedItem in pastedItems)
                {
                    _context._componentService.RaiseComponentRegisteredAndAddedToContainer(pastedItem);
                }


                changeGroup.Commit();
            }
        }