Browse Source

Added xaml parser support for collections in attached properties.

pull/77/head
gumme 12 years ago
parent
commit
14dd5a9a43
  1. 16
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/ExampleService.cs
  2. 19
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SimpleLoadTests.cs
  3. 27
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs
  4. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlPropertyInfo.cs

16
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/ExampleService.cs

@ -26,6 +26,22 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -26,6 +26,22 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
TestHelperLog.Log("ExampleService.SetExample");
element.SetValue(ExampleProperty, value);
}
public static readonly DependencyProperty ExampleCollectionProperty = DependencyProperty.RegisterAttached(
"ExampleCollection", typeof(ExampleClassList), typeof(ExampleService)
);
public static ExampleClassList GetExampleCollection(DependencyObject element)
{
TestHelperLog.Log("ExampleService.GetExampleCollection");
return (ExampleClassList)element.GetValue(ExampleCollectionProperty);
}
public static void SetExampleCollection(DependencyObject element, ExampleClassList value)
{
TestHelperLog.Log("ExampleService.SetExampleCollection");
element.SetValue(ExampleCollectionProperty, value);
}
}
public class ExampleDependencyObject : DependencyObject

19
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SimpleLoadTests.cs

@ -221,6 +221,25 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -221,6 +221,25 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
");
}
[Test]
public void ExampleServiceCollectionTest()
{
TestLoading(@"
<t:ExampleDependencyObject
xmlns=""http://schemas.microsoft.com/netfx/2007/xaml/presentation""
xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @"""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<t:ExampleService.ExampleCollection>
<t:ExampleClassList>
<t:ExampleClass OtherProp=""a""> </t:ExampleClass>
<t:ExampleClass OtherProp=""b"" />
<t:ExampleClass OtherProp=""c"" />
</t:ExampleClassList>
</t:ExampleService.ExampleCollection>
</t:ExampleDependencyObject>
");
}
[Test]
public void ExampleClassObjectPropWithStringValue()
{

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

@ -276,15 +276,21 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -276,15 +276,21 @@ namespace ICSharpCode.WpfDesign.XamlDom
obj.Properties.Where((prop) => prop.IsResources).FirstOrDefault() != null;
}
XmlElement CreatePropertyElement()
{
string ns = parentObject.OwnerDocument.GetNamespaceFor(parentObject.ElementType);
return parentObject.OwnerDocument.XmlDocument.CreateElement(
parentObject.OwnerDocument.GetPrefixForNamespace(ns),
parentObject.ElementType.Name + "." + this.PropertyName,
ns
);
}
XmlElement CreatePropertyElement()
{
Type propertyElementType = GetPropertyElementType();
string ns = parentObject.OwnerDocument.GetNamespaceFor(propertyElementType);
return parentObject.OwnerDocument.XmlDocument.CreateElement(
parentObject.OwnerDocument.GetPrefixForNamespace(ns),
propertyElementType.Name + "." + this.PropertyName,
ns
);
}
Type GetPropertyElementType()
{
return this.IsAttached ? this.PropertyTargetType : parentObject.ElementType;
}
static XmlNode FindChildNode(XmlNode node, string localName, string namespaceURI)
{
@ -305,7 +311,8 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -305,7 +311,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
if (this.IsCollection) {
if (IsNodeCollectionForThisProperty(newChildNode)) {
XmlNode parentNode = FindChildNode(parentObject.XmlElement, parentObject.ElementType.Name + "." + this.PropertyName, parentObject.OwnerDocument.GetNamespaceFor(parentObject.ElementType));
Type propertyElementType = GetPropertyElementType();
XmlNode parentNode = FindChildNode(parentObject.XmlElement, propertyElementType.Name + "." + this.PropertyName, parentObject.OwnerDocument.GetNamespaceFor(propertyElementType));
if (parentNode == null) {
parentNode = CreatePropertyElement();

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlPropertyInfo.cs

@ -39,6 +39,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -39,6 +39,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
readonly DependencyProperty property;
readonly bool isAttached;
readonly bool isCollection;
public override DependencyProperty DependencyProperty {
get { return property; }
@ -49,6 +50,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -49,6 +50,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
Debug.Assert(property != null);
this.property = property;
this.isAttached = isAttached;
this.isCollection = CollectionSupport.IsCollectionType(property.PropertyType);
}
public override TypeConverter TypeConverter {
@ -84,7 +86,9 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -84,7 +86,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
public override bool IsCollection {
get { return false; }
get {
return isCollection;
}
}
public override object GetValue(object instance)

Loading…
Cancel
Save