protected DesignItem CreateGridContextWithDesignSurface(string xaml) { var surface = new DesignSurface(); var xamlWithGrid = @"<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" > " + xaml + "</Grid>"; surface.LoadDesigner(new XmlTextReader(new StringReader(xamlWithGrid)), new XamlLoadSettings()); Assert.IsNotNull(surface.DesignContext.RootItem); return(surface.DesignContext.RootItem); }
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); try { settings.ReportErrors = UpdateTasks; designer.LoadDesigner(r, settings); designer.ContextMenuOpening += (sender, e) => MenuService.ShowContextMenu(e.OriginalSource as UIElement, designer, "/AddIns/WpfDesign/Designer/ContextMenu"); 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); } } }
void UpdateDesign() { OutlineRoot = null; using (var xmlReader = XmlReader.Create(new StringReader(Text))) { DesignSurface.LoadDesigner(xmlReader, null); } if (DesignContext.RootItem != null) { OutlineRoot = OutlineNode.Create(DesignContext.RootItem); UndoService.UndoStackChanged += new EventHandler(UndoService_UndoStackChanged); } RaisePropertyChanged("SelectionService"); RaisePropertyChanged("XamlErrorService"); }
void UpdateDesign() { OutlineRoot = null; using (var xmlReader = XmlReader.Create(new StringReader(Text))) { XamlLoadSettings settings = new XamlLoadSettings(); foreach (var assNode in Toolbox.Instance.AssemblyNodes) { settings.DesignerAssemblies.Add(assNode.Assembly); } settings.TypeFinder = MyTypeFinder.Instance; DesignSurface.LoadDesigner(xmlReader, settings); } if (DesignContext.RootItem != null) { OutlineRoot = OutlineNode.Create(DesignContext.RootItem); UndoService.UndoStackChanged += new EventHandler(UndoService_UndoStackChanged); } RaisePropertyChanged("SelectionService"); RaisePropertyChanged("XamlErrorService"); }
protected DesignItem CreateGridContextWithDesignSurface(string xaml) { var surface = new DesignSurface(); var xamlWithGrid=@"<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" > " + xaml + "</Grid>"; surface.LoadDesigner(new XmlTextReader(new StringReader(xamlWithGrid)), new XamlLoadSettings()); Assert.IsNotNull(surface.DesignContext.RootItem); return surface.DesignContext.RootItem; }
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); 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); } try{ 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")) { node.Attributes.Append(att); } } var appXamlXml = XmlReader.Create(new StringReader(node.InnerXml)); var parsed = XamlParser.Parse(appXamlXml, ((XamlDesignContext)designer.DesignContext).ParserSettings); var dict = (ResourceDictionary)parsed.RootInstance; designer.DesignPanel.Resources.MergedDictionaries.Add(dict); } } catch (Exception ex) { LoggingService.Error("Error in loading app.xaml", ex); } } }