public virtual void Paste(DesignContext designContext) { XamlDesignContext xamlContext = designContext as XamlDesignContext; if (xamlContext != null) { xamlContext.XamlEditAction.Paste(); } }
public void Paste() { XamlDesignContext xamlContext = _designContext as XamlDesignContext; if (xamlContext != null) { xamlContext.XamlEditAction.Paste(); } }
protected DesignItem CreateGridContext(string xaml) { XamlDesignContext context = CreateContext(@"<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" > " + xaml + "</Grid>"); var grid = (Grid)context.RootItem.Component; var gridChild = context.Services.Component.GetDesignItem(grid.Children[0]); return(gridChild); }
public void Cut() { XamlDesignContext xamlContext = _designContext as XamlDesignContext; ISelectionService selectionService = GetService <ISelectionService>(); if (xamlContext != null && selectionService != null) { xamlContext.XamlEditAction.Cut(selectionService.SelectedItems); } }
public virtual void Copy(DesignContext designContext) { XamlDesignContext xamlContext = designContext as XamlDesignContext; ISelectionService selectionService = designContext.Services.GetService <ISelectionService>(); if (xamlContext != null && selectionService != null && !selectionService.SelectedItems.Contains(designContext.RootItem)) { xamlContext.XamlEditAction.Copy(selectionService.SelectedItems); } }
protected XamlDesignContext CreateContext(string xaml) { log = new StringBuilder(); XamlDesignContext context = new XamlDesignContext(new XmlTextReader(new StringReader(xaml)), new XamlLoadSettings()); /*context.Services.Component.ComponentRegistered += delegate(object sender, DesignItemEventArgs e) { * log.AppendLine("Register " + ItemIdentity(e.Item)); * }; * context.Services.Component.ComponentUnregistered += delegate(object sender, DesignItemEventArgs e) { * log.AppendLine("Unregister " + ItemIdentity(e.Item)); * };*/ return(context); }
protected DesignItem CreateCanvasContext(string xaml) { XamlDesignContext context = CreateContext(@"<Canvas xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> " + xaml + "</Canvas>"); Canvas canvas = (Canvas)context.RootItem.Component; DesignItem canvasChild = context.Services.Component.GetDesignItem(canvas.Children[0]); Assert.IsNotNull(canvasChild); return(canvasChild); }
protected XamlDesignContext CreateContext(string xaml) { log = new StringBuilder(); XamlDesignContext context = new XamlDesignContext(new XmlTextReader(new StringReader(xaml)), CreateXamlLoadSettings()); /*context.Services.Component.ComponentRegistered += delegate(object sender, DesignItemEventArgs e) { * log.AppendLine("Register " + ItemIdentity(e.Item)); * }; * context.Services.Component.ComponentUnregistered += delegate(object sender, DesignItemEventArgs e) { * log.AppendLine("Unregister " + ItemIdentity(e.Item)); * };*/ // create required service mocks var designPanel = MockRepository.GenerateStub <IDesignPanel>(); designPanel.Stub(dp => dp.Adorners).Return(new System.Collections.Generic.List <AdornerPanel>()); context.Services.AddService(typeof(IDesignPanel), designPanel); return(context); }
protected override void LoadInternal(OpenedFile file, System.IO.Stream stream) { wasChangedInDesigner = false; Debug.Assert(file == this.PrimaryFile); SD.AnalyticsMonitor.TrackFeature(typeof(WpfViewContent), "Load"); _stream = new MemoryStream(); stream.CopyTo(_stream); stream.Position = 0; if (designer == null) { // initialize designer on first load designer = new DesignSurface(); this.UserContent = designer; InitPropertyEditor(); InitWpfToolbox(); } this.UserContent = designer; if (outline != null) { outline.Root = null; } using (XmlTextReader r = new XmlTextReader(stream)) { XamlLoadSettings settings = new XamlLoadSettings(); settings.DesignerAssemblies.Add(typeof(WpfViewContent).Assembly); settings.CustomServiceRegisterFunctions.Add( delegate(XamlDesignContext context) { context.Services.AddService(typeof(IUriContext), new FileUriContext(this.PrimaryFile)); context.Services.AddService(typeof(IPropertyDescriptionService), new PropertyDescriptionService(this.PrimaryFile)); context.Services.AddService(typeof(IEventHandlerService), new SharpDevelopEventHandlerService(this)); context.Services.AddService(typeof(ITopLevelWindowService), new WpfAndWinFormsTopLevelWindowService()); context.Services.AddService(typeof(ChooseClassServiceBase), new IdeChooseClassService()); }); settings.TypeFinder = MyTypeFinder.Create(this.PrimaryFile); settings.CurrentProjectAssemblyName = SD.ProjectService.CurrentProject.AssemblyName; try { if (WpfEditorOptions.EnableAppXamlParsing) { var appXaml = SD.ProjectService.CurrentProject.Items.FirstOrDefault(x => x.FileName.GetFileName().ToLower() == ("app.xaml")); if (appXaml != null) { var f = appXaml as FileProjectItem; OpenedFile a = SD.FileService.GetOrCreateOpenedFile(f.FileName); var xml = XmlReader.Create(a.OpenRead()); var doc = new XmlDocument(); doc.Load(xml); var node = doc.FirstChild.ChildNodes.Cast <XmlNode>().FirstOrDefault(x => x.Name == "Application.Resources"); foreach (XmlAttribute att in doc.FirstChild.Attributes.Cast <XmlAttribute>().ToList()) { if (att.Name.StartsWith("xmlns")) { foreach (var childNode in node.ChildNodes.OfType <XmlNode>()) { childNode.Attributes.Append(att); } } } var appXamlXml = XmlReader.Create(new StringReader(node.InnerXml)); var appxamlContext = new XamlDesignContext(appXamlXml, settings); //var parsed = XamlParser.Parse(appXamlXml, appxamlContext.ParserSettings); var dict = (ResourceDictionary)appxamlContext.RootItem.Component; // parsed.RootInstance; designer.DesignPanel.Resources.MergedDictionaries.Add(dict); } } } catch (Exception ex) { LoggingService.Error("Error in loading app.xaml", ex); } try { settings.ReportErrors = UpdateTasks; designer.LoadDesigner(r, settings); designer.DesignPanel.ContextMenuHandler = (contextMenu) => { var newContextmenu = new ContextMenu(); var sdContextMenuItems = MenuService.CreateMenuItems(newContextmenu, designer, "/AddIns/WpfDesign/Designer/ContextMenu", "ContextMenu"); foreach (var entry in sdContextMenuItems) { newContextmenu.Items.Add(entry); } newContextmenu.Items.Add(new Separator()); var items = contextMenu.Items.Cast <Object>().ToList(); contextMenu.Items.Clear(); foreach (var entry in items) { newContextmenu.Items.Add(entry); } designer.DesignPanel.ContextMenu = newContextmenu; }; if (outline != null && designer.DesignContext != null && designer.DesignContext.RootItem != null) { outline.Root = OutlineNode.Create(designer.DesignContext.RootItem); } propertyGridView.PropertyGrid.SelectedItems = null; designer.DesignContext.Services.Selection.SelectionChanged += OnSelectionChanged; designer.DesignContext.Services.GetService <UndoService>().UndoStackChanged += OnUndoStackChanged; } catch (Exception e) { this.UserContent = new WpfDocumentError(e); } } }