• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# XamlDom.XamlObject类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: UpdateXmlAttribute

		bool UpdateXmlAttribute(bool force, out XamlObject holder)
		{
			holder = FindXmlAttributeHolder();
			if (holder == null && force && IsMarkupExtension) {
				holder = this;
			}
			if (holder != null && MarkupExtensionPrinter.CanPrint(holder)) {
				var s = MarkupExtensionPrinter.Print(holder);
				holder.XmlAttribute = holder.ParentProperty.SetAttribute(s);
				return true;
			}
			return false;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:13,代码来源:XamlObject.cs


示例17: ParseComplete

		/// <summary>
		/// Called by XamlParser to finish initializing the document.
		/// </summary>
		internal void ParseComplete(XamlObject rootElement)
		{
			this._rootElement = rootElement;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:7,代码来源:XamlDocument.cs


示例18: CreateObjectFromAttributeText

		internal static object CreateObjectFromAttributeText(string valueText, XamlPropertyInfo targetProperty, XamlObject scope)
		{
			if (targetProperty.ReturnType == typeof(Uri)) {
				return scope.OwnerDocument.TypeFinder.ConvertUriToLocalUri(new Uri(valueText, UriKind.RelativeOrAbsolute));
			} else if (targetProperty.ReturnType == typeof(ImageSource)) {
				var uri = scope.OwnerDocument.TypeFinder.ConvertUriToLocalUri(new Uri(valueText, UriKind.RelativeOrAbsolute));
				return targetProperty.TypeConverter.ConvertFromString(scope.OwnerDocument.GetTypeDescriptorContext(scope), CultureInfo.InvariantCulture, uri.ToString());
			}

			return targetProperty.TypeConverter.ConvertFromString(
				scope.OwnerDocument.GetTypeDescriptorContext(scope),
				CultureInfo.InvariantCulture, valueText);
		}
开发者ID:lvv83,项目名称:SharpDevelop,代码行数:13,代码来源:XamlParser.cs


示例19: GetNonMarkupExtensionParent

		private static XamlObject GetNonMarkupExtensionParent(XamlObject markupExtensionObject)
		{
			System.Diagnostics.Debug.Assert(markupExtensionObject.IsMarkupExtension);
			
			XamlObject obj = markupExtensionObject;
			while (obj != null && obj.IsMarkupExtension) {
				obj = obj.ParentObject;
			}
			return obj;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:10,代码来源:MarkupExtensionPrinter.cs


示例20: RemoveRootNamespacesFromNodeAndChildNodes

		/// <summary>
		/// Removes namespace attributes defined in the root from the specified node and all child nodes.
		/// </summary>
		static void RemoveRootNamespacesFromNodeAndChildNodes(XamlObject root, XmlNode node)
		{
			foreach (XmlNode childNode in node.ChildNodes) {
				RemoveRootNamespacesFromNodeAndChildNodes(root, childNode);
			}

			if (node.Attributes != null) {
				List<XmlAttribute> removeAttributes = new List<XmlAttribute>();
				foreach (XmlAttribute attrib in node.Attributes) {
					if (attrib.Name.StartsWith("xmlns:")) {
						var rootPrefix = root.OwnerDocument.GetPrefixForNamespace(attrib.Value);
						if (rootPrefix == null) {
							//todo: check if we can add to root, (maybe same ns exists)
							root.OwnerDocument.XmlDocument.Attributes.Append((XmlAttribute)attrib.CloneNode(true));
							removeAttributes.Add(attrib);
						}
						else if (rootPrefix == attrib.Name.Substring("xmlns:".Length)) {
							removeAttributes.Add(attrib);
						}
					}
					else if (attrib.Name == "xmlns" && attrib.Value == XamlConstants.PresentationNamespace) {
						removeAttributes.Add(attrib);
					}
				}
				foreach (var removeAttribute in removeAttributes) {
					node.Attributes.Remove(removeAttribute);
				}
			}
		}
开发者ID:lvv83,项目名称:SharpDevelop,代码行数:32,代码来源:XamlParser.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# XamlBinding.XamlCompletionContext类代码示例发布时间:2022-05-26
下一篇:
C# WixBinding.WixDocument类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap