当前位置: 首页>>代码示例>>C#>>正文


C# XamlDom.XamlObject类代码示例

本文整理汇总了C#中ICSharpCode.WpfDesign.XamlDom.XamlObject的典型用法代码示例。如果您正苦于以下问题:C# XamlObject类的具体用法?C# XamlObject怎么用?C# XamlObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XamlObject类属于ICSharpCode.WpfDesign.XamlDom命名空间,在下文中一共展示了XamlObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: XamlObjectServiceProvider

		/// <summary>
		/// Creates a new XamlObjectServiceProvider instance.
		/// </summary>
		public XamlObjectServiceProvider(XamlObject obj)
		{
			if (obj == null)
				throw new ArgumentNullException("obj");
			XamlObject = obj;
			Resolver = new XamlTypeResolverProvider(obj);
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:10,代码来源:XamlObjectServiceProvider.cs

示例2: NameChanged

		/// <summary>
		/// Finds the XAML namescope for the specified object and uses it to unregister the old name and then register the new name.
		/// </summary>
		/// <param name="namedObject">The object where the name was changed.</param>
		/// <param name="oldName">The old name.</param>
		/// <param name="newName">The new name.</param>
		public static void NameChanged(XamlObject namedObject, string oldName, string newName)
		{
			var obj = namedObject;
			while (obj != null) {
				var nameScope = obj.Instance as INameScope;
				if (nameScope == null) {
					var depObj = obj.Instance as DependencyObject;
					if (depObj != null)
						nameScope = NameScope.GetNameScope(depObj);
				}
				if (nameScope != null) {
					if (oldName != null) {
						try {
							nameScope.UnregisterName(oldName);
						} catch (Exception x) {
							Debug.WriteLine(x.Message);
						}
					}
					if (newName != null) {
						nameScope.RegisterName(newName, namedObject.Instance);
						
						try{
							var prp = namedObject.ElementType.GetProperty(namedObject.RuntimeNameProperty);
							if (prp != null)
								prp.SetValue(namedObject.Instance, newName, null);
						} catch (Exception x) {
							Debug.WriteLine(x.Message);
						}
					}
					break;
				}
				obj = obj.ParentObject;
			}
		}
开发者ID:netide,项目名称:SharpDevelop,代码行数:40,代码来源:NameScopeHelper.cs

示例3: XamlTypeResolverProvider

		public XamlTypeResolverProvider(XamlObject containingObject)
		{
			if (containingObject == null)
				throw new ArgumentNullException("containingObject");
			this.document = containingObject.OwnerDocument;
			this.containingObject = containingObject;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:7,代码来源:XamlTypeResolverProvider.cs

示例4: Print

		/// <summary>
		/// Generates XAML markup extension code for the object.
		/// </summary>
		public static string Print(XamlObject obj)
		{
			StringBuilder sb = new StringBuilder();
			sb.Append("{");
			sb.Append(obj.GetNameForMarkupExtension());

			bool first = true;
			foreach (var property in obj.Properties) {
				if (!property.IsSet) continue;

				if (first)
					sb.Append(" ");
				else
					sb.Append(", ");
				first = false;

				sb.Append(property.GetNameForMarkupExtension());
				sb.Append("=");

				var value = property.PropertyValue;
				if (value is XamlTextValue) {
					sb.Append((value as XamlTextValue).Text);
				} else if (value is XamlObject) {
					sb.Append(Print(value as XamlObject));
				}
			}
			sb.Append("}");
			return sb.ToString();
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:32,代码来源:MarkupExtensionPrinter.cs

示例5: GetXaml

        /// <summary>
        /// Gets the Xaml string of the <paramref name="xamlObject"/>
        /// </summary>
        /// <param name="xamlObject">The object whose Xaml is requested.</param>
        public static string GetXaml(XamlObject xamlObject)
        {
            if (xamlObject != null)
            {
                var nd = xamlObject.XmlElement.CloneNode(true);
                var attLst = nd.Attributes.Cast<XmlAttribute>().ToDictionary(x => x.Name);

                var ns = new List<XmlAttribute>();

                var parentObject = xamlObject.ParentObject;
                while (parentObject != null)
                {
                    foreach (XmlAttribute attribute in parentObject.XmlElement.Attributes)
                    {
                        if (attribute.Name.StartsWith("xmlns:"))
                        {
                            if (!attLst.ContainsKey(attribute.Name))
                            {
                                nd.Attributes.Append((XmlAttribute)attribute.CloneNode(false));
                                attLst.Add(attribute.Name, attribute);
                            }
                        }
                    }
                    parentObject = parentObject.ParentObject;
                }

                return nd.OuterXml;
            }
            return null;
        }
开发者ID:icsharpcode,项目名称:WpfDesigner,代码行数:34,代码来源:XamlStaticTools.cs

示例6: MarkupExtensionWrapper

		/// <summary>
		/// Initializes a new instance.
		/// </summary>
		/// <param name="xamlObject">The <see cref="XamlObject"/> object that represents the markup extension.</param>
		protected MarkupExtensionWrapper(XamlObject xamlObject)
		{
			if (xamlObject == null) {
				throw new ArgumentNullException("xamlObject");
			}
			
			XamlObject = xamlObject;
		}
开发者ID:modulexcite,项目名称:WpfDesigner,代码行数:12,代码来源:MarkupExtensionWrapper.cs

示例7: CanPrint

		/// <summary>
		/// Gets whether shorthand XAML markup extension code can be generated for the object.
		/// </summary>
		public static bool CanPrint(XamlObject obj)
		{
			if (obj.ElementType == typeof(System.Windows.Data.MultiBinding) ||
			    obj.ElementType == typeof(System.Windows.Data.PriorityBinding)) {
				return false;
			}
			
			return CanPrint(obj, false, GetNonMarkupExtensionParent(obj));
		}
开发者ID:modulexcite,项目名称:WpfDesigner,代码行数:12,代码来源:MarkupExtensionPrinter.cs

示例8: XamlProperty

		internal XamlProperty(XamlObject parentObject, XamlPropertyInfo propertyInfo)
		{
			this.parentObject = parentObject;
			this.propertyInfo = propertyInfo;
			
			if (propertyInfo.IsCollection) {
				isCollection = true;
				collectionElements = new CollectionElementsCollection(this);
			}
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:10,代码来源:XamlProperty.cs

示例9: DummyTypeDescriptorContext

			public DummyTypeDescriptorContext(XamlDocument document, XamlObject containingObject)
			{
				if (containingObject != null) {
					if (containingObject.OwnerDocument != document)
						throw new ArgumentException("Containing object must belong to the document!");
					baseServiceProvider = containingObject.ServiceProvider;
				} else {
					baseServiceProvider = document.ServiceProvider;
				}
			}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:10,代码来源:XamlDocument.cs

示例10: Print

		/// <summary>
		/// Generates XAML markup extension code for the object.
		/// </summary>
		public static string Print(XamlObject obj)
		{
			StringBuilder sb = new StringBuilder();
			sb.Append("{");
			sb.Append(obj.GetNameForMarkupExtension());

			bool first = true;
			var properties = obj.Properties.ToList();
			
			if (obj.ElementType == typeof(Binding)){
				var p=obj.Properties.FirstOrDefault(x=>x.PropertyName=="Path");
				if (p!=null && p.IsSet) {
					sb.Append(" ");
					AppendPropertyValue(sb, p.PropertyValue, false);
					properties.Remove(p);
					first = false;
				}
			}
			else if (obj.ElementType == typeof(Reference)){
				var p=obj.Properties.FirstOrDefault(x=>x.PropertyName=="Name");
				if (p!=null && p.IsSet) {
					sb.Append(" ");
					AppendPropertyValue(sb, p.PropertyValue, false);
					properties.Remove(p);
					first = false;
				}
			}
			else if (obj.ElementType == typeof(StaticResourceExtension)){
				var p=obj.Properties.FirstOrDefault(x=>x.PropertyName=="ResourceKey");
				if (p!=null && p.IsSet) {
					sb.Append(" ");
					AppendPropertyValue(sb, p.PropertyValue, false);
					properties.Remove(p);
					first = false;
				}
			}
			
			foreach (var property in properties) {
				if (!property.IsSet) continue;

				if (first)
					sb.Append(" ");
				else
					sb.Append(", ");
				first = false;

				sb.Append(property.GetNameForMarkupExtension());
				sb.Append("=");

				AppendPropertyValue(sb, property.PropertyValue, property.ReturnType == typeof(string));
			}
			sb.Append("}");
			return sb.ToString();
		}
开发者ID:modulexcite,项目名称:WpfDesigner,代码行数:57,代码来源:MarkupExtensionPrinter.cs

示例11: GetTypeDescriptorContext

		/// <summary>
		/// Gets the type descriptor context used for type conversions.
		/// </summary>
		/// <param name="containingObject">The containing object, used when the
		/// type descriptor context needs to resolve an XML namespace.</param>
		internal ITypeDescriptorContext GetTypeDescriptorContext(XamlObject containingObject)
		{
			IServiceProvider serviceProvider;
			if (containingObject != null) {
				if (containingObject.OwnerDocument != this)
					throw new ArgumentException("Containing object must belong to the document!");
				serviceProvider = containingObject.ServiceProvider;
			} else {
				serviceProvider = this.ServiceProvider;
			}
			return new DummyTypeDescriptorContext(serviceProvider);
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:17,代码来源:XamlDocument.cs

示例12: XamlProperty

		internal XamlProperty(XamlObject parentObject, XamlPropertyInfo propertyInfo)
		{
			this.parentObject = parentObject;
			this.propertyInfo = propertyInfo;
			
			if (propertyInfo.IsCollection) {
				isCollection = true;
				collectionElements = new CollectionElementsCollection(this);
				
				if (propertyInfo.Name.Equals(XamlConstants.ResourcesPropertyName, StringComparison.Ordinal) &&
				    propertyInfo.ReturnType == typeof(ResourceDictionary)) {
					isResources = true;
				}
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:15,代码来源:XamlProperty.cs

示例13: Print

		/// <summary>
		/// Generates XAML markup extension code for the object.
		/// </summary>
		public static string Print(XamlObject obj)
		{
			StringBuilder sb = new StringBuilder();
			sb.Append("{");
			sb.Append(obj.GetNameForMarkupExtension());

			bool first = true;
			foreach (var property in obj.Properties) {
				if (!property.IsSet) continue;

				if (first)
					sb.Append(" ");
				else
					sb.Append(", ");
				first = false;

				sb.Append(property.GetNameForMarkupExtension());
				sb.Append("=");

				var value = property.PropertyValue;
				var textValue = value as XamlTextValue;
				if (textValue != null) {
					string text = textValue.Text;
					bool containsSpace = text.Contains(' ');
					
					if(containsSpace) {
						sb.Append('\'');
					}
					
					sb.Append(text.Replace("\\", "\\\\"));
					
					if(containsSpace) {
						sb.Append('\'');
					}
				} else if (value is XamlObject) {
					sb.Append(Print(value as XamlObject));
				}
			}
			sb.Append("}");
			return sb.ToString();
		}
开发者ID:fanyjie,项目名称:SharpDevelop,代码行数:44,代码来源:MarkupExtensionPrinter.cs

示例14: CanPrint

		/// <summary>
		/// Gets whether shorthand XAML markup extension code can be generated for the object.
		/// </summary>
		public static bool CanPrint(XamlObject obj)
		{
			if (obj.ElementType == typeof(System.Windows.Data.MultiBinding) ||
				obj.ElementType == typeof(System.Windows.Data.PriorityBinding)) {
				return false;
			}
			
			foreach (var property in obj.Properties.Where((prop) => prop.IsSet))
			{
				var value = property.PropertyValue;
				if (value is XamlTextValue)
					continue;
				else
				{
					XamlObject xamlObject = value as XamlObject;
					if (xamlObject == null || !xamlObject.IsMarkupExtension)
						return false;
					else {
						var staticResource = xamlObject.Instance as System.Windows.StaticResourceExtension;
						if (staticResource != null &&
							staticResource.ResourceKey != null) {
							XamlObject parent = GetNonMarkupExtensionParent(xamlObject);
							
							if (parent != null) {
								var parentLocalResource = parent.ServiceProvider.Resolver.FindLocalResource(staticResource.ResourceKey);
								
								// If resource with the specified key is declared locally on the same object as the StaticResource is being used the markup extension
								// must be printed as element to find the resource, otherwise it will search from parent-parent and find none or another resource.
								if (parentLocalResource != null)
									return false;
							}
						}
					}
				}
			}

			return true;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:41,代码来源:MarkupExtensionPrinter.cs

示例15: GetNameScopeFromObject

		/// <summary>
		/// Gets the XAML namescope for the specified object.
		/// </summary>
		/// <param name="obj">The object to get the XAML namescope for.</param>
		/// <returns>A XAML namescope, as an <see cref="INameScope"/> instance.</returns>
		public static INameScope GetNameScopeFromObject(XamlObject obj)
		{
			INameScope nameScope = null;

			while (obj != null)
			{
				nameScope = obj.Instance as INameScope;
				if (nameScope == null)
				{
					var xamlObj = obj.ParentObject != null ? obj.ParentObject : obj;
					var depObj = xamlObj.Instance as DependencyObject;
					if (depObj != null)
						nameScope = NameScope.GetNameScope(depObj);

					if (nameScope != null)
						break;
				}

				obj = obj.ParentObject;
			}

			return nameScope;
		}
开发者ID:modulexcite,项目名称:WpfDesigner,代码行数:28,代码来源:NameScopeHelper.cs


注:本文中的ICSharpCode.WpfDesign.XamlDom.XamlObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。