Browse Source

Support for Styles in WPF Designer

Fix Unittest "ListBox2"
fixes #587
pull/586/head
jogibear9988 11 years ago
parent
commit
1952626a1e
  1. 11
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
  2. 36
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs
  3. 23
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs
  4. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs
  5. 32
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

11
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs

@ -85,11 +85,12 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -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 {

36
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs

@ -22,10 +22,12 @@ using System.Collections.ObjectModel; @@ -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 @@ -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 @@ -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 @@ -353,7 +385,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// Gets/Sets the name of this XamlObject.
/// </summary>
public string Name {
get
get
{
string name = GetXamlAttribute("Name");

23
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs

@ -141,7 +141,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -141,7 +141,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
public AmbientPropertyValue GetFirstAmbientValue(IEnumerable<XamlType> 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 @@ -151,7 +151,23 @@ namespace ICSharpCode.WpfDesign.XamlDom
public IEnumerable<AmbientPropertyValue> GetAllAmbientValues(IEnumerable<XamlType> ceilingTypes, params XamlMember[] properties)
{
return new List<AmbientPropertyValue>();
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<object> GetAllAmbientValues(params XamlType[] types)
@ -159,8 +175,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -159,8 +175,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
return new List<object>();
}
public IEnumerable<AmbientPropertyValue> GetAllAmbientValues(IEnumerable<XamlType> ceilingTypes, bool searchLiveStackOnly, IEnumerable<XamlType> types,
params XamlMember[] properties)
public IEnumerable<AmbientPropertyValue> GetAllAmbientValues(IEnumerable<XamlType> ceilingTypes, bool searchLiveStackOnly, IEnumerable<XamlType> types, params XamlMember[] properties)
{
return new List<AmbientPropertyValue>();
}

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs

@ -289,9 +289,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -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();

32
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

@ -21,8 +21,11 @@ using System.Collections.Generic; @@ -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 @@ -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 @@ -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;
}
}
/// <summary>
/// Resets the properties value.
/// </summary>

Loading…
Cancel
Save