diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs index 064a4bb77c..01b71be2f6 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs @@ -85,11 +85,12 @@ namespace ICSharpCode.WpfDesign.XamlDom } else if (collectionInstance is IDictionary) { object val = newElement.GetValueFor(null); object key = newElement is XamlObject ? ((XamlObject)newElement).GetXamlAttribute("Key") : null; - //if (key == null || key == "") { - // if (val is Style) - // key = ((Style)val).TargetType; - //} - if (key == null || (key as string) == "") + if (key == null || key == "") + { + if (val is Style) + key = ((Style)val).TargetType; + } + if (key == null || (key as string) == "") key = val; ((IDictionary)collectionInstance).Add(key, val); } else { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs index 66f9c34056..1ff20e9a43 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs @@ -22,10 +22,12 @@ using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Linq; +using System.Reflection; using System.Windows.Markup; using System.Xml; using System.Windows.Data; using System.Windows; +using System.Xaml; namespace ICSharpCode.WpfDesign.XamlDom { @@ -53,6 +55,7 @@ namespace ICSharpCode.WpfDesign.XamlDom this.instance = instance; this.contentPropertyName = GetContentPropertyName(elementType); + XamlSetTypeConverter = GetTypeConverterDelegate(elementType); ServiceProvider = new XamlObjectServiceProvider(this); CreateWrapper(); @@ -183,7 +186,36 @@ namespace ICSharpCode.WpfDesign.XamlDom return null; } - + + internal delegate void TypeConverterDelegate(Object targetObject, XamlSetTypeConverterEventArgs eventArgs); + + internal TypeConverterDelegate XamlSetTypeConverter { get; private set; } + + internal static TypeConverterDelegate GetTypeConverterDelegate(Type elementType) + { + var attrs = elementType.GetCustomAttributes(typeof(XamlSetTypeConverterAttribute), true) as XamlSetTypeConverterAttribute[]; + if (attrs != null && attrs.Length > 0) + { + var name = attrs[0].XamlSetTypeConverterHandler; + var method=elementType.GetMethod(name, BindingFlags.Static|BindingFlags.Public|BindingFlags.NonPublic); + + return (TypeConverterDelegate) TypeConverterDelegate.CreateDelegate(typeof(TypeConverterDelegate), method); + } + + return null; + } + + private XamlType _systemXamlTypeForProperty = null; + public XamlType SystemXamlTypeForProperty + { + get + { + if (_systemXamlTypeForProperty == null) + _systemXamlTypeForProperty = new XamlType(this.ElementType, this.ServiceProvider.SchemaContext); + return _systemXamlTypeForProperty; + } + } + internal override void AddNodeTo(XamlProperty property) { XamlObject holder; @@ -353,7 +385,7 @@ namespace ICSharpCode.WpfDesign.XamlDom /// Gets/Sets the name of this XamlObject. /// public string Name { - get + get { string name = GetXamlAttribute("Name"); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs index 5337340e34..1b05165a23 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs @@ -141,7 +141,7 @@ namespace ICSharpCode.WpfDesign.XamlDom public AmbientPropertyValue GetFirstAmbientValue(IEnumerable ceilingTypes, params XamlMember[] properties) { - return null; + return GetAllAmbientValues(ceilingTypes, properties).FirstOrDefault(); } public object GetFirstAmbientValue(params XamlType[] types) @@ -151,7 +151,23 @@ namespace ICSharpCode.WpfDesign.XamlDom public IEnumerable GetAllAmbientValues(IEnumerable ceilingTypes, params XamlMember[] properties) { - return new List(); + var obj = this.XamlObject.ParentObject; + + while (obj != null) + { + if (ceilingTypes.Any(x => obj.SystemXamlTypeForProperty.CanAssignTo(x))) + { + foreach (var pr in obj.Properties) + { + if (properties.Any(x => x.Name == pr.PropertyName)) + { + yield return new AmbientPropertyValue(pr.SystemXamlMemberForProperty, pr.ValueOnInstance); + } + } + } + + obj = obj.ParentObject; + } } public IEnumerable GetAllAmbientValues(params XamlType[] types) @@ -159,8 +175,7 @@ namespace ICSharpCode.WpfDesign.XamlDom return new List(); } - public IEnumerable GetAllAmbientValues(IEnumerable ceilingTypes, bool searchLiveStackOnly, IEnumerable types, - params XamlMember[] properties) + public IEnumerable GetAllAmbientValues(IEnumerable ceilingTypes, bool searchLiveStackOnly, IEnumerable types, params XamlMember[] properties) { return new List(); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs index d601293f82..b43125e912 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs @@ -289,9 +289,7 @@ namespace ICSharpCode.WpfDesign.XamlDom ParseObjectAttribute(obj, attribute); } - if (!(obj.Instance is Style)) { - ParseObjectContent(obj, element, defaultProperty, initializeFromTextValueInsteadOfConstructor); - } + ParseObjectContent(obj, element, defaultProperty, initializeFromTextValueInsteadOfConstructor); if (iSupportInitializeInstance != null) { iSupportInitializeInstance.EndInit(); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs index 8379cbd291..802195fcdb 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs @@ -21,8 +21,11 @@ using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; +using System.Reflection; using System.Xml; using System.Windows; +using System.Windows.Markup; +using System.Xaml; namespace ICSharpCode.WpfDesign.XamlDom { @@ -203,7 +206,7 @@ namespace ICSharpCode.WpfDesign.XamlDom propertyValue.ParentProperty = this; propertyValue.AddNodeTo(this); UpdateValueOnInstance(); - + ParentObject.OnPropertyChanged(this); if (!wasSet) { @@ -222,13 +225,38 @@ namespace ICSharpCode.WpfDesign.XamlDom if (PropertyValue != null) { try { ValueOnInstance = PropertyValue.GetValueFor(propertyInfo); + + if (this.parentObject.XamlSetTypeConverter != null) + this.ParentObject.XamlSetTypeConverter(this.parentObject.Instance, new XamlSetTypeConverterEventArgs(this.SystemXamlMemberForProperty, null, ((XamlTextValue) propertyValue).Text, this.parentObject.OwnerDocument.GetTypeDescriptorContext(this.parentObject), null)); } catch { Debug.WriteLine("UpdateValueOnInstance() failed"); } } } - + + private XamlMember _systemXamlMemberForProperty = null; + public XamlMember SystemXamlMemberForProperty + { + get + { + if (_systemXamlMemberForProperty == null) + _systemXamlMemberForProperty = new XamlMember(this.PropertyName, SystemXamlTypeForProperty, false); + return _systemXamlMemberForProperty; + } + } + + private XamlType _systemXamlTypeForProperty = null; + public XamlType SystemXamlTypeForProperty + { + get + { + if (_systemXamlTypeForProperty == null) + _systemXamlTypeForProperty = new XamlType(this.PropertyTargetType, + this.ParentObject.ServiceProvider.SchemaContext); + return _systemXamlTypeForProperty; + } + } /// /// Resets the properties value. ///