The design context implementation used when editing XAML.
Inheritance: DesignContext
Exemplo n.º 1
0
		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;
		}
Exemplo n.º 2
0
		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;
		}
Exemplo n.º 3
0
 public XamlDesignItem(XamlObject xamlObject, XamlDesignContext designContext)
 {
     this._xamlObject    = xamlObject;
     this._designContext = designContext;
     this._properties    = new XamlModelPropertyCollection(this);
 }
Exemplo n.º 4
0
		public XamlDesignItem(XamlObject xamlObject, XamlDesignContext designContext)
		{
			this._xamlObject = xamlObject;
			this._designContext = designContext;
			this._properties = new XamlModelPropertyCollection(this);
		}
 public XamlModelCollectionElementsCollection(XamlModelProperty modelProperty, XamlProperty property)
 {
     this.modelProperty = modelProperty;
     this.property      = property;
     this.context       = (XamlDesignContext)modelProperty.DesignItem.Context;
 }
Exemplo n.º 6
0
 public XamlEditOperations(XamlDesignContext context, XamlParserSettings settings)
 {
     this._context  = context;
     this._settings = settings;
 }
Exemplo n.º 7
0
 public XamlComponentService(XamlDesignContext context)
 {
     this._context = context;
 }
Exemplo n.º 8
0
		public XamlEditOperations(XamlDesignContext context, XamlParserSettings settings)
		{
			this._context = context;
			this._settings = settings;
		}
Exemplo n.º 9
0
		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);
				}
			}
		}