internal void UpdateAdvanceOptionsForItem(MarkupObject markupObject, DependencyObject dependencyObject, DependencyPropertyDescriptor dpDescriptor, out object tooltip) { tooltip = StringConstants.AdvancedProperties; bool isResource = false; bool isDynamicResource = false; var markupProperty = markupObject.Properties.FirstOrDefault(p => p.Name == PropertyName); if (markupProperty != null) { //TODO: need to find a better way to determine if a StaticResource has been applied to any property not just a style(maybe with StaticResourceExtension) isResource = typeof(Style).IsAssignableFrom(markupProperty.PropertyType); isDynamicResource = typeof(DynamicResourceExtension).IsAssignableFrom(markupProperty.PropertyType); } if (isResource || isDynamicResource) { tooltip = StringConstants.Resource; } else { if ((dependencyObject != null) && (dpDescriptor != null)) { if (BindingOperations.GetBindingExpressionBase(dependencyObject, dpDescriptor.DependencyProperty) != null) { tooltip = StringConstants.Databinding; } else { BaseValueSource bvs = DependencyPropertyHelper .GetValueSource(dependencyObject, dpDescriptor.DependencyProperty) .BaseValueSource; switch (bvs) { case BaseValueSource.Inherited: case BaseValueSource.DefaultStyle: case BaseValueSource.ImplicitStyleReference: tooltip = StringConstants.Inheritance; break; case BaseValueSource.DefaultStyleTrigger: break; case BaseValueSource.Style: tooltip = StringConstants.StyleSetter; break; case BaseValueSource.Local: tooltip = StringConstants.Local; break; } } } } }
private static List <DependencyProperty> GetAttachedProperties(Object element) { MarkupObject markupObject = MarkupWriter.GetMarkupObjectFor(element); return((from mp in markupObject.Properties where mp.IsAttached select mp.DependencyProperty).ToList()); }
internal DescriptorPropertyDefinition(PropertyDescriptor propertyDescriptor, IPropertyParent propertyParent) : base(propertyParent) { if (propertyDescriptor == null) { throw new ArgumentNullException("propertyDescriptor"); } _propertyDescriptor = propertyDescriptor; _dpDescriptor = DependencyPropertyDescriptor.FromProperty(propertyDescriptor); _markupObject = MarkupWriter.GetMarkupObjectFor(_propertyParent.ValueInstance); }
private void Init( PropertyDescriptor propertyDescriptor, object selectedObject ) { if( propertyDescriptor == null ) throw new ArgumentNullException( "propertyDescriptor" ); if( selectedObject == null ) throw new ArgumentNullException( "selectedObject" ); _propertyDescriptor = propertyDescriptor; _selectedObject = selectedObject; _dpDescriptor = DependencyPropertyDescriptor.FromProperty( propertyDescriptor ); _markupObject = MarkupWriter.GetMarkupObjectFor( SelectedObject ); }
// ========================================================================== private void SaveObject(XmlElement parent, MarkupObject markupObject) { XmlElement element = Document.CreateElement(GetNamespacePrefix(markupObject.ObjectType), markupObject.ObjectType.Name, GetNamespaceUri(markupObject.ObjectType)); parent.AppendChild(element); foreach (MarkupProperty property in markupObject.Properties) { SaveProperty(element, markupObject, property); } }
/// <summary> /// Returns the property that is being edited in the element for example editing Window Title returns "Title", /// Button text as "Content". /// </summary> private string PropertyUpdated(TextBlock text) { MarkupObject obj = MarkupWriter.GetMarkupObjectFor(designItem.Component); foreach (MarkupProperty property in obj.Properties) { if (property.DependencyProperty != null && property.StringValue == textBlock.Text) { return(property.Name); } } return(null); }
private void WriteObject(object key, object obj, XmlTextWriter writer, bool isRoot) { MarkupObject markupObj = MarkupWriter.GetMarkupObjectFor(obj); Type objectType = markupObj.ObjectType; _namespaceCache.GetXmlNamespace(objectType); string ns = _namespaceCache.GetXmlNamespace(objectType); string prefix = _namespaceCache.GetPrefixForNamespace(ns); WriteStartElement(writer, prefix, markupObj.ObjectType.Name); if (isRoot) { foreach (NamespaceMap map in _namespaceMaps.Values) { if (string.IsNullOrEmpty(map.Prefix)) { writer.WriteAttributeString("xmlns", map.XmlNamespace); } else { writer.WriteAttributeString("xmlns:" + map.Prefix, map.XmlNamespace); } } if (!_namespaceMaps.ContainsKey(NamespaceCache.XamlNamespace)) { writer.WriteAttributeString("xmlns:x", NamespaceCache.XamlNamespace); } } if (key != null) { string keyString = key.ToString(); if (keyString.Length > 0) { writer.WriteAttributeString("x:Key", keyString); } else { //TODO: key may not be a string, what about x:Type... throw new NotImplementedException(); } } WriteProperties(writer, markupObj); writer.WriteEndElement(); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyItem"/> class. /// </summary> public PropertyItem(PropertyDescriptor property, object instance) { Property = property; Instance = instance; ResetCommand = new Command <object>(ResetValue, CanResetValue); EditBindingCommand = new Command <object>(ShowBindingEditor, o => !property.IsReadOnly); EditResourceCommand = new Command <object>(ShowResourceEditor, o => !property.IsReadOnly); _propertySortInfo = PropertySorter.GetSortInfo(property); _markupObject = MarkupWriter.GetMarkupObjectFor(Instance); property.AddValueChanged(instance, OnValueChanged); _dpd = DependencyPropertyDescriptor.FromProperty(property); }
public static List <DependencyProperty> GetAttachedProperties(Object element) { List <DependencyProperty> attachedProperties = new List <DependencyProperty>(); MarkupObject markupObject = MarkupWriter.GetMarkupObjectFor(element); if (markupObject != null) { foreach (MarkupProperty mp in markupObject.Properties) { if (mp.IsAttached) { attachedProperties.Add(mp.DependencyProperty); } } } return(attachedProperties); }
private void ResolveXmlNamespaces(object obj) { MarkupObject markupObj = MarkupWriter.GetMarkupObjectFor(obj); string ns = _namespaceCache.GetXmlNamespace(markupObj.ObjectType); string prefix = _namespaceCache.GetPrefixForNamespace(ns); _namespaceMaps[ns] = new NamespaceMap(prefix, ns); foreach (MarkupProperty markupProperty in markupObj.Properties) { if (IsContentProperty(markupObj, markupProperty)) { if (!(markupProperty.Value is String)) { ResolveChildXmlNamespaces(markupProperty); } continue; } if (markupProperty.Value.GetType() == typeof(NullExtension) || markupProperty.IsValueAsString) { continue; } if (!markupProperty.IsComposite) { if (markupProperty.DependencyProperty != null) { string ns1 = _namespaceCache.GetXmlNamespace(markupProperty.DependencyProperty.OwnerType); string prefix1 = _namespaceCache.GetPrefixForNamespace(ns1); if (!string.IsNullOrEmpty(prefix1)) { _namespaceMaps[ns1] = new NamespaceMap(prefix1, ns1); } } } else { string ns2 = _namespaceCache.GetXmlNamespace(markupObj.ObjectType); string prefix2 = _namespaceCache.GetPrefixForNamespace(ns2); _namespaceMaps[ns2] = new NamespaceMap(prefix2, ns2); ResolveChildXmlNamespaces(markupProperty); } } }
//https://stackoverflow.com/questions/4794071/how-to-enumerate-all-dependency-properties-of-control public static IEnumerable <DependencyProperty> EnumerateAttachedProperties(object element) { if (element != null) { MarkupObject markupObject = MarkupWriter.GetMarkupObjectFor(element); if (markupObject != null) { foreach (MarkupProperty mp in markupObject.Properties) { if (mp.IsAttached) { yield return(mp.DependencyProperty); } } } } }
/// <summary> /// </summary> /// <param name="element"></param> /// <returns></returns> public static List <DependencyProperty> GetDependencyProperties(Object element) { List <DependencyProperty> properties = new List <DependencyProperty>(); MarkupObject markupObject = MarkupWriter.GetMarkupObjectFor(element); if (markupObject is not null) { foreach (MarkupProperty mp in markupObject.Properties) { if (mp.DependencyProperty is not null) { properties.Add(mp.DependencyProperty); } } } return(properties); }
internal DescriptorPropertyDefinition(PropertyDescriptor propertyDescriptor, object selectedObject, bool isPropertyGridCategorized) : base(isPropertyGridCategorized) { if (propertyDescriptor == null) { throw new ArgumentNullException("propertyDescriptor"); } if (selectedObject == null) { throw new ArgumentNullException("selectedObject"); } _propertyDescriptor = propertyDescriptor; _selectedObject = selectedObject; _dpDescriptor = DependencyPropertyDescriptor.FromProperty(propertyDescriptor); _markupObject = MarkupWriter.GetMarkupObjectFor(SelectedObject); }
public static List <DependencyProperty> GetDependencyProperties(Object element) { List <DependencyProperty> properties = new List <DependencyProperty>(); MarkupObject markupObject = MarkupWriter.GetMarkupObjectFor(element); if (markupObject != null) { foreach (MarkupProperty mp in markupObject.Properties) { Console.WriteLine("{1} : MarkupProperty = {0}", mp.Name, element); if (mp.DependencyProperty != null) { properties.Add(mp.DependencyProperty); } } } return(properties); }
private string GetContentPropertyName(MarkupObject markupObj) { Type objectType = markupObj.ObjectType; if (!_contentPropertiesCache.ContainsKey(objectType)) { string lookedUpContentProperty = string.Empty; foreach (Attribute attr in markupObj.Attributes) { ContentPropertyAttribute cpa = attr as ContentPropertyAttribute; if (cpa != null) { lookedUpContentProperty = cpa.Name; break; //Once content property is found, come out of the loop. } } _contentPropertiesCache.Add(objectType, lookedUpContentProperty); } return(_contentPropertiesCache[objectType]); }
public void WriteObject(object key, object obj, XmlWriter writer, bool isRoot) { var doc = xmldoc.DocumentElement; List <MarkupProperty> propertyElements = new List <MarkupProperty>(); MarkupProperty contentProperty = null; string contentPropertyName = null; MarkupObject markupObj = MarkupWriter.GetMarkupObjectFor(obj); Type objectType = markupObj.ObjectType; string ns = _namespaceCache.GetNamespaceUriFor(objectType); string prefix = _namespaceCache.GetDefaultPrefixFor(ns); if (isRoot) { if (String.IsNullOrEmpty(prefix)) { if (String.IsNullOrEmpty(ns)) { writer.WriteStartElement(markupObj.ObjectType.Name, NamespaceCache.DefaultNamespace); writer.WriteAttributeString("xmlns", NamespaceCache.XmlnsNamespace, NamespaceCache.DefaultNamespace); } else { writer.WriteStartElement(markupObj.ObjectType.Name, ns); writer.WriteAttributeString("xmlns", NamespaceCache.XmlnsNamespace, ns); } } else { if (doc.LocalName == markupObj.ObjectType.Name) { if (doc.NamespaceURI == ns) { if (doc.Prefix == prefix) { } } } } //writer.WriteAttributeString("xmlns", "x", // NamespaceCache.XmlnsNamespace, NamespaceCache.XamlNamespace); //foreach (NamespaceMap map in _dicNamespaceMap.Values) { // if (!String.IsNullOrEmpty(map.Prefix) && !String.Equals(map.Prefix, "x")) // writer.WriteAttributeString("xmlns", map.Prefix, NamespaceCache.XmlnsNamespace, map.XmlNamespace); //} } else { //TODO: Fix - the best way to handle this case... if (markupObj.ObjectType.Name == "PathFigureCollection" && markupObj.Instance != null) { WriteState writeState = writer.WriteState; if (writeState == WriteState.Element) { writer.WriteAttributeString("Figures", markupObj.Instance.ToString()); } else { if (String.IsNullOrEmpty(prefix)) { writer.WriteStartElement("PathGeometry.Figures"); } else { writer.WriteStartElement("PathGeometry.Figures", ns); } writer.WriteString(markupObj.Instance.ToString()); writer.WriteEndElement(); } return; } else { if (String.IsNullOrEmpty(prefix)) { writer.WriteStartElement(markupObj.ObjectType.Name); } else { writer.WriteStartElement(markupObj.ObjectType.Name, ns); } } } // Add the x:Name for object like Geometry/Drawing not derived from FrameworkElement... DependencyObject dep = obj as DependencyObject; if (dep != null) { string nameValue = dep.GetValue(FrameworkElement.NameProperty) as string; if (!String.IsNullOrEmpty(nameValue) && !(dep is FrameworkElement)) { writer.WriteAttributeString("x", "Name", NamespaceCache.XamlNamespace, nameValue); } } if (key != null) { string keyString = key.ToString(); if (keyString.Length > 0) { writer.WriteAttributeString("x", "Key", NamespaceCache.XamlNamespace, keyString); } else { //TODO: key may not be a string, what about x:Type... throw new NotImplementedException( "Sample XamlWriter cannot yet handle keys that aren't strings"); } } //Look for CPA info in our cache that keeps contentProperty names per Type //If it doesn't have an entry, go get the info and store it. if (!_contentProperties.ContainsKey(objectType)) { string lookedUpContentProperty = String.Empty; foreach (Attribute attr in markupObj.Attributes) { ContentPropertyAttribute cpa = attr as ContentPropertyAttribute; if (cpa != null) { lookedUpContentProperty = cpa.Name; //Once content property is found, come out of the loop. break; } } _contentProperties.Add(objectType, lookedUpContentProperty); } contentPropertyName = _contentProperties[objectType]; string contentString = String.Empty; foreach (MarkupProperty markupProperty in markupObj.Properties) { if (markupProperty.Name != contentPropertyName) { if (markupProperty.IsValueAsString) { contentString = markupProperty.Value as string; } else if (!markupProperty.IsComposite) { string temp = markupProperty.StringValue; if (markupProperty.IsAttached) { string ns1 = _namespaceCache.GetNamespaceUriFor(markupProperty.DependencyProperty.OwnerType); string prefix1 = _namespaceCache.GetDefaultPrefixFor(ns1); if (String.IsNullOrEmpty(prefix1)) { writer.WriteAttributeString(markupProperty.Name, temp); } else { writer.WriteAttributeString(markupProperty.Name, ns1, temp); } } else { if (markupProperty.Name == "FontUri" && (_wpfSettings != null)) { string fontUri = temp.ToLower(); fontUri = fontUri.Replace(_windowsDir, _windowsPath); StringBuilder builder = new StringBuilder(); builder.Append("{"); builder.Append("svg"); builder.Append(":"); builder.Append("SvgFontUri "); builder.Append(fontUri); builder.Append("}"); writer.WriteAttributeString(markupProperty.Name, builder.ToString()); } else { if (doc.HasAttribute(markupProperty.Name)) { PropertyInfo pI = obj.GetType().GetProperty(markupProperty.Name); SetValue(pI, doc, obj); } } } } else if (markupProperty.Value.GetType() == _nullType) { if (_nullExtension) { //writer.WriteAttributeString(markupProperty.Name, "{x:Null}"); } } else { propertyElements.Add(markupProperty); } } else { contentProperty = markupProperty; } } if (contentProperty != null || propertyElements.Count > 0 || contentString != String.Empty) { foreach (MarkupProperty markupProp in propertyElements) { string propElementName = markupObj.ObjectType.Name + "." + markupProp.Name; if (doc.HasChildNodes) { foreach (XmlElement child in doc.ChildNodes) { if (child.LocalName == propElementName) { if (child.HasChildNodes) { foreach (XmlElement _child in child.ChildNodes) { string _namespace = _child.NamespaceURI; string _prefix = _child.Prefix; string _nameType = _namespace + "." + _child.LocalName; if (IsKnowType(_nameType)) { Type _type = Type.GetType(_nameType); object _obj = _type.InvokeMember(_type.FullName, BindingFlags.CreateInstance, null, null, null); Create(_type, _child, _obj); IList collection = markupProp.Value as IList; IDictionary dictionary = markupProp.Value as IDictionary; if (collection != null) { collection.Add(_obj); } } } } } } } } if (contentString != String.Empty) { //writer.WriteValue(contentString); } else if (contentProperty != null) { if (contentProperty.Value is string) { //writer.WriteValue(contentProperty.StringValue); } else { //WriteChildren(writer, contentProperty); } } } //writer.WriteEndElement(); }
private void XmlWrite(XmlWriter xmlw, object obj, bool isRoot) { MarkupObject markupObj = MarkupWriter.GetMarkupObjectFor(obj); Type objectType = markupObj.ObjectType; if (isRoot) { string nspace = objectType.Namespace; xmlw.WriteStartElement(objectType.Name, nspace); } List <MarkupProperty> propertyElements = new List <MarkupProperty>(); foreach (System.Windows.Markup.Primitives.MarkupProperty markupProp in markupObj.Properties) { try { if (!markupProp.IsComposite) { string temp = markupProp.StringValue; if (!string.IsNullOrEmpty(temp)) { xmlw.WriteAttributeString(markupProp.Name, temp); } } else if (markupProp.Value.GetType() == typeof(System.Windows.Markup.NullExtension)) { if (_nullExtension) { xmlw.WriteAttributeString(markupProp.Name, "{x:Null}"); } } else { propertyElements.Add(markupProp); //XmlWrite(xmlw, markupProp.Value, false); } } catch { } } if (propertyElements.Count > 0) { foreach (MarkupProperty markupProp in propertyElements) { string propElementName = markupObj.ObjectType.Name + "." + markupProp.Name; if (isRoot) { xmlw.WriteStartElement(propElementName); } System.Collections.IList collection = markupProp.Value as System.Collections.IList; System.Collections.IDictionary dictionary = markupProp.Value as System.Collections.IDictionary; if (collection != null && collection.Count > 0) { foreach (object iobj in collection) { XmlWrite(xmlw, iobj, true); xmlw.WriteEndElement(); } } else if (dictionary != null && dictionary.Count > 0) { foreach (object iobj in dictionary) { XmlWrite(xmlw, iobj, true); xmlw.WriteEndElement(); } } else { if (markupProp.Value.GetType() == typeof(Equip) || markupProp.Value.GetType() == typeof(Solution)) { XmlWrite(xmlw, markupProp.Value, true); } xmlw.WriteEndElement(); } } } }
// ========================================================================== /// <summary> /// Initializes a new instance of the <see cref="XamlSerializer"/> class. /// </summary> /// <param name="instance">The instance.</param> public XamlSerializer(object instance) { MarkupObject = MarkupWriter.GetMarkupObjectFor(instance); }
private void ResolveXmlNamespaces(object obj) { List <MarkupProperty> propertyElements = new List <MarkupProperty>(); MarkupProperty contentProperty = null; string contentPropertyName = null; MarkupObject markupObj = MarkupWriter.GetMarkupObjectFor(obj); Type objectType = markupObj.ObjectType; string ns = _namespaceCache.GetNamespaceUriFor(objectType); if (!string.IsNullOrWhiteSpace(ns)) { string prefix = _namespaceCache.GetDefaultPrefixFor(ns); _dicNamespaceMap[ns] = new NamespaceMap(prefix, ns); } //Look for CPA info in our cache that keeps contentProperty names per Type //If it doesn't have an entry, go get the info and store it. if (!_contentProperties.ContainsKey(objectType)) { string lookedUpContentProperty = string.Empty; foreach (Attribute attr in markupObj.Attributes) { ContentPropertyAttribute cpa = attr as ContentPropertyAttribute; if (cpa != null) { lookedUpContentProperty = cpa.Name; //Once content property is found, come out of the loop. break; } } _contentProperties.Add(objectType, lookedUpContentProperty); } contentPropertyName = _contentProperties[objectType]; string contentString = string.Empty; foreach (MarkupProperty markupProperty in markupObj.Properties) { if (markupProperty.Name != contentPropertyName) { if (markupProperty.IsValueAsString) { contentString = markupProperty.Value as string; } else if (!markupProperty.IsComposite) { //Bug Fix DX-0120123 if (markupProperty.DependencyProperty != null) { string ns1 = _namespaceCache.GetNamespaceUriFor( markupProperty.DependencyProperty.OwnerType); string prefix1 = _namespaceCache.GetDefaultPrefixFor(ns1); if (!string.IsNullOrWhiteSpace(prefix1)) { _dicNamespaceMap[ns1] = new NamespaceMap(prefix1, ns1); } } } else if (markupProperty.Value.GetType() == _nullType) { } else { propertyElements.Add(markupProperty); } } else { contentProperty = markupProperty; } } if (contentProperty != null || propertyElements.Count > 0 || contentString != string.Empty) { foreach (MarkupProperty markupProp in propertyElements) { string ns2 = _namespaceCache.GetNamespaceUriFor(markupObj.ObjectType); if (!string.IsNullOrWhiteSpace(ns2)) { string prefix2 = _namespaceCache.GetDefaultPrefixFor(ns2); _dicNamespaceMap[ns2] = new NamespaceMap(prefix2, ns2); } ResolveChildXmlNamespaces(markupProp); } if (contentProperty != null) { if (!(contentProperty.Value is String)) { ResolveChildXmlNamespaces(contentProperty); } } } }
private void WriteObject(object key, object obj, XmlWriter writer, bool isRoot) { List <MarkupProperty> propertyElements = new List <MarkupProperty>(); MarkupProperty contentProperty = null; string contentPropertyName = null; MarkupObject markupObj = MarkupWriter.GetMarkupObjectFor(obj); Type objectType = markupObj.ObjectType; string ns = _namespaceCache.GetNamespaceUriFor(objectType); string prefix = _namespaceCache.GetDefaultPrefixFor(ns); if (isRoot) { if (string.IsNullOrWhiteSpace(prefix)) { if (string.IsNullOrWhiteSpace(ns)) { writer.WriteStartElement(markupObj.ObjectType.Name, NamespaceCache.DefaultNamespace); writer.WriteAttributeString("xmlns", NamespaceCache.XmlnsNamespace, NamespaceCache.DefaultNamespace); } else { writer.WriteStartElement(markupObj.ObjectType.Name, ns); writer.WriteAttributeString("xmlns", NamespaceCache.XmlnsNamespace, ns); } } else { writer.WriteStartElement(prefix, markupObj.ObjectType.Name, ns); } writer.WriteAttributeString("xmlns", "x", NamespaceCache.XmlnsNamespace, NamespaceCache.XamlNamespace); foreach (NamespaceMap map in _dicNamespaceMap.Values) { if (!string.IsNullOrWhiteSpace(map.Prefix) && !string.Equals(map.Prefix, "x")) { writer.WriteAttributeString("xmlns", map.Prefix, NamespaceCache.XmlnsNamespace, map.XmlNamespace); } } } else { //TODO: Fix - the best way to handle this case... if (markupObj.ObjectType.Name == "PathFigureCollection" && markupObj.Instance != null) { WriteState writeState = writer.WriteState; if (writeState == WriteState.Element) { //writer.WriteAttributeString("Figures", // markupObj.Instance.ToString()); writer.WriteAttributeString("Figures", System.Convert.ToString(markupObj.Instance, _culture)); } else { if (string.IsNullOrWhiteSpace(prefix)) { writer.WriteStartElement("PathGeometry.Figures"); } else { writer.WriteStartElement("PathGeometry.Figures", ns); } //writer.WriteString(markupObj.Instance.ToString()); writer.WriteString(System.Convert.ToString( markupObj.Instance, _culture)); writer.WriteEndElement(); } return; } else { if (string.IsNullOrWhiteSpace(prefix)) { writer.WriteStartElement(markupObj.ObjectType.Name); } else { writer.WriteStartElement(markupObj.ObjectType.Name, ns); } } } // Add the x:Name for object like Geometry/Drawing not derived from FrameworkElement... DependencyObject dep = obj as DependencyObject; if (dep != null) { string nameValue = dep.GetValue(FrameworkElement.NameProperty) as string; if (!string.IsNullOrWhiteSpace(nameValue) && !(dep is FrameworkElement)) { writer.WriteAttributeString("x", "Name", NamespaceCache.XamlNamespace, nameValue); } } if (key != null) { string keyString = key.ToString(); if (keyString.Length > 0) { writer.WriteAttributeString("x", "Key", NamespaceCache.XamlNamespace, keyString); } else { //TODO: key may not be a string, what about x:Type... throw new NotImplementedException( "Sample XamlWriter cannot yet handle keys that aren't strings"); } } //Look for CPA info in our cache that keeps contentProperty names per Type //If it doesn't have an entry, go get the info and store it. if (!_contentProperties.ContainsKey(objectType)) { string lookedUpContentProperty = string.Empty; foreach (Attribute attr in markupObj.Attributes) { ContentPropertyAttribute cpa = attr as ContentPropertyAttribute; if (cpa != null) { lookedUpContentProperty = cpa.Name; //Once content property is found, come out of the loop. break; } } _contentProperties.Add(objectType, lookedUpContentProperty); } contentPropertyName = _contentProperties[objectType]; string contentString = string.Empty; foreach (MarkupProperty markupProperty in markupObj.Properties) { if (markupProperty.Name != contentPropertyName) { if (markupProperty.IsValueAsString) { contentString = markupProperty.Value as string; } else if (!markupProperty.IsComposite) { string temp = markupProperty.StringValue; if (markupProperty.IsAttached) { string ns1 = _namespaceCache.GetNamespaceUriFor(markupProperty.DependencyProperty.OwnerType); string prefix1 = _namespaceCache.GetDefaultPrefixFor(ns1); if (temp.IndexOfAny("{}".ToCharArray()) >= 0) { temp = "{}" + temp; } if (string.IsNullOrWhiteSpace(prefix1)) { writer.WriteAttributeString(markupProperty.Name, temp); } else { writer.WriteAttributeString(markupProperty.Name, ns1, temp); } } else { if (markupProperty.Name == "FontUri" && (_wpfSettings != null && _wpfSettings.IncludeRuntime)) { string fontUri = temp.ToLower(); fontUri = fontUri.Replace(_windowsDir, _windowsPath); StringBuilder builder = new StringBuilder(); builder.Append("{"); builder.Append("svg"); builder.Append(":"); builder.Append("SvgFontUri "); builder.Append(fontUri.Replace('\\', '/')); builder.Append("}"); writer.WriteAttributeString(markupProperty.Name, builder.ToString()); } else { if (temp.IndexOfAny("{}".ToCharArray()) >= 0) { temp = "{}" + temp; } writer.WriteAttributeString(markupProperty.Name, temp); } } } else if (markupProperty.Value.GetType() == _nullType) { if (_nullExtension) { writer.WriteAttributeString(markupProperty.Name, "{x:Null}"); } } else { propertyElements.Add(markupProperty); } } else { contentProperty = markupProperty; } } if (contentProperty != null || propertyElements.Count > 0 || contentString != string.Empty) { foreach (MarkupProperty markupProp in propertyElements) { string ns2 = _namespaceCache.GetNamespaceUriFor(markupObj.ObjectType); string prefix2 = null; if (!string.IsNullOrWhiteSpace(ns2)) { prefix2 = _namespaceCache.GetDefaultPrefixFor(ns2); } string propElementName = markupObj.ObjectType.Name + "." + markupProp.Name; if (string.IsNullOrWhiteSpace(prefix2)) { writer.WriteStartElement(propElementName); } else { writer.WriteStartElement(prefix2, propElementName, ns2); } WriteChildren(writer, markupProp); writer.WriteEndElement(); } if (contentString != string.Empty) { writer.WriteValue(contentString); } else if (contentProperty != null) { if (contentProperty.Value is string) { writer.WriteValue(contentProperty.StringValue); } else { WriteChildren(writer, contentProperty); } } } writer.WriteEndElement(); }
//========================================================================== private void SaveProperty(XmlElement parent, MarkupObject markupObject, MarkupProperty property) { Binding binding = null; if (property.DependencyProperty != null) { // If this property is a DependencyProperty markupObject.Instance... // ...must be a DepedencyObject binding = BindingOperations.GetBinding(markupObject.Instance as DependencyObject, property.DependencyProperty); } if (binding != null) { SaveBindingProperty(parent, property, binding); } else { string content_property_name = null; // Get the content property of markupObject.Instance... if (property.PropertyDescriptor == null) { // SavePropertyContent(parent, property); //return; SaveAttributeProperty(parent, property); return; } if (property.PropertyDescriptor.GetType().ToString() == "System.ComponentModel.ReflectPropertyDescriptor") { //bool breaker = false; if (property.PropertyType.Name == "Object") { if (!property.IsAttached) { /*foreach (var item in property.Attributes) * { * if (item is System.Runtime.InteropServices.ClassInterfaceAttribute) * { * breaker = true; * } * }*/ //if (property.IsComposite) { try { if (property.IsComposite) //if (property.StringValue == null) { } } catch (Exception) { //SaveCompositeProperty(parent, property); return; } } } } // SavePropertyContent(parent, property); //return; //SaveAttributeProperty(parent, property); //return; } //try { object[] attributes = property.PropertyDescriptor.ComponentType.GetCustomAttributes(typeof(ContentPropertyAttribute), true); if (attributes.Length > 0) { ContentPropertyAttribute attribute = attributes[attributes.Length - 1] as ContentPropertyAttribute; content_property_name = attribute.Name; } if (content_property_name == property.Name) { // Only store the property's content SavePropertyContent(parent, property); } else if (property.IsComposite) { // Save property using its own element SaveCompositeProperty(parent, property); } else { // Save as attribute SaveAttributeProperty(parent, property); } } /*catch (Exception ex) * { * MessageBox.Show(ex.ToString()); * }*/ } }
private bool IsContentProperty(MarkupObject markupObj, MarkupProperty markupProperty) { return(markupProperty.Name == GetContentPropertyName(markupObj)); }
internal void UpdateAdvanceOptionsForItem(MarkupObject markupObject, DependencyObject dependencyObject, DependencyPropertyDescriptor dpDescriptor, out string imageName, out object tooltip) { imageName = "AdvancedProperties11"; tooltip = "Advanced Properties"; bool isResource = false; bool isDynamicResource = false; var markupProperty = markupObject.Properties.Where(p => p.Name == PropertyName).FirstOrDefault(); if (markupProperty != null) { //TODO: need to find a better way to determine if a StaticResource has been applied to any property not just a style isResource = (markupProperty.Value is Style); isDynamicResource = (markupProperty.Value is DynamicResourceExtension); } if (isResource || isDynamicResource) { imageName = "Resource11"; tooltip = "Resource"; } else { if ((dependencyObject != null) && (dpDescriptor != null)) { if (BindingOperations.GetBindingExpressionBase(dependencyObject, dpDescriptor.DependencyProperty) != null) { imageName = "Database11"; tooltip = "Databinding"; } else { BaseValueSource bvs = DependencyPropertyHelper .GetValueSource(dependencyObject, dpDescriptor.DependencyProperty) .BaseValueSource; switch (bvs) { case BaseValueSource.Inherited: case BaseValueSource.DefaultStyle: case BaseValueSource.ImplicitStyleReference: imageName = "Inheritance11"; tooltip = "Inheritance"; break; case BaseValueSource.DefaultStyleTrigger: break; case BaseValueSource.Style: imageName = "Style11"; tooltip = "Style Setter"; break; case BaseValueSource.Local: imageName = "Local11"; tooltip = "Local"; break; } } } } }
private void WriteObject(object key, object obj, XmlTextWriter writer, bool isRoot) { MarkupObject markupObj = MarkupWriter.GetMarkupObjectFor(obj); Type objectType = markupObj.ObjectType; _namespaceCache.GetXmlNamespace(objectType); string ns = _namespaceCache.GetXmlNamespace(objectType); string prefix = _namespaceCache.GetPrefixForNamespace(ns); WriteStartElement(writer, prefix, markupObj.ObjectType.Name); if (isRoot) { foreach (NamespaceMap map in _namespaceMaps.Values) { if (string.IsNullOrEmpty(map.Prefix)) { writer.WriteAttributeString("xmlns", map.XmlNamespace); } else { writer.WriteAttributeString("xmlns:" + map.Prefix, map.XmlNamespace); } } if (!_namespaceMaps.ContainsKey(NamespaceCache.XamlNamespace)) { writer.WriteAttributeString("xmlns:x", NamespaceCache.XamlNamespace); } } if (key != null) { string keyString = key.ToString(); if (keyString.Length > 0) { writer.WriteAttributeString("x:Key", keyString); } else { //TODO: key may not be a string, what about x:Type... throw new NotImplementedException(); } } List <MarkupProperty> propertyElements = new List <MarkupProperty>(); MarkupProperty contentProperty = null; string contentString = string.Empty; foreach (MarkupProperty markupProperty in markupObj.Properties) { if (IsContentProperty(markupObj, markupProperty)) { contentProperty = markupProperty; continue; } if (markupProperty.IsValueAsString) { contentString = markupProperty.Value as string; } else if (!markupProperty.IsComposite) { string temp = markupProperty.Value == null ? string.Empty : _formatterConverter.ToString(markupProperty.Value); if (markupProperty.IsAttached) { string ns1 = _namespaceCache.GetXmlNamespace(markupProperty.DependencyProperty.OwnerType); string prefix1 = _namespaceCache.GetPrefixForNamespace(ns1); if (string.IsNullOrEmpty(prefix1)) { writer.WriteAttributeString(markupProperty.Name, temp); } else { writer.WriteAttributeString(prefix1 + ":" + markupProperty.Name, temp); } } else { if (markupProperty.Name == "Name" && NamespaceCache.GetAssemblyNameFromType(markupProperty.DependencyProperty.OwnerType).Equals("PresentationFramework")) { writer.WriteAttributeString("x:" + markupProperty.Name, temp); } else { writer.WriteAttributeString(markupProperty.Name, temp); } } } else if (markupProperty.Value.GetType() == typeof(NullExtension)) { writer.WriteAttributeString(markupProperty.Name, "{x:Null}"); } else { propertyElements.Add(markupProperty); } } if (contentProperty != null || propertyElements.Count > 0 || !string.IsNullOrEmpty(contentString)) { foreach (MarkupProperty markupProp in propertyElements) { string ns2 = _namespaceCache.GetXmlNamespace(markupObj.ObjectType); string prefix2 = _namespaceCache.GetPrefixForNamespace(ns2); string propElementName = markupObj.ObjectType.Name + "." + markupProp.Name; WriteStartElement(writer, prefix2, propElementName); WriteChildren(writer, markupProp); writer.WriteEndElement(); } if (!string.IsNullOrEmpty(contentString)) { writer.WriteValue(contentString); } else if (contentProperty != null) { if (contentProperty.Value is string) { writer.WriteValue(contentProperty.StringValue); } else { WriteChildren(writer, contentProperty); } } } writer.WriteEndElement(); }
private void WriteProperties(XmlTextWriter writer, MarkupObject markupObj) { List <MarkupProperty> propertyElements = new List <MarkupProperty>(); MarkupProperty contentProperty = null; string contentString = string.Empty; foreach (MarkupProperty markupProperty in markupObj.Properties) { if (IsContentProperty(markupObj, markupProperty)) { contentProperty = markupProperty; continue; } if (markupProperty.IsValueAsString) { contentString = markupProperty.Value as string; } else if (!markupProperty.IsComposite) { string temp = markupProperty.Value == null ? string.Empty : markupProperty.Value.ToString(); if (markupProperty.IsAttached) { string ns1 = _namespaceCache.GetXmlNamespace(markupProperty.DependencyProperty.OwnerType); string prefix1 = _namespaceCache.GetPrefixForNamespace(ns1); if (string.IsNullOrEmpty(prefix1)) { writer.WriteAttributeString(markupProperty.Name, temp); } else { writer.WriteAttributeString(prefix1 + ":" + markupProperty.Name, temp); } } else { DependencyProperty dependencyProperty = markupProperty.DependencyProperty; Type ownerType = dependencyProperty == null ? null : dependencyProperty.OwnerType; if (markupProperty.Name == "Name" && ownerType != null && NamespaceCache.GetAssemblyNameFromType(ownerType).Equals("PresentationFramework")) { writer.WriteAttributeString("x:" + markupProperty.Name, temp); } else { writer.WriteAttributeString(markupProperty.Name, temp); } } } else if (markupProperty.Value.GetType() == typeof(NullExtension)) { writer.WriteAttributeString(markupProperty.Name, "{x:Null}"); } else { propertyElements.Add(markupProperty); } } if (contentProperty != null || propertyElements.Count > 0 || !string.IsNullOrEmpty(contentString)) { foreach (MarkupProperty markupProp in propertyElements) { string ns2 = _namespaceCache.GetXmlNamespace(markupObj.ObjectType); string prefix2 = _namespaceCache.GetPrefixForNamespace(ns2); string propElementName = markupObj.ObjectType.Name + "." + markupProp.Name; WriteStartElement(writer, prefix2, propElementName); WriteChildren(writer, markupProp); writer.WriteEndElement(); } if (!string.IsNullOrEmpty(contentString)) { writer.WriteValue(contentString); } else if (contentProperty != null) { if (contentProperty.Value is string) { writer.WriteValue(contentProperty.StringValue); } else { WriteChildren(writer, contentProperty); } } } }