Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit fadbc15

Browse files
Merge pull request #442 from gumme/WpfDesignerParserFixes
XamlParser now supports attached property used on a derived class.
2 parents 1b1a773 + 85a4c46 commit fadbc15

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,25 @@ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
6767
// TODO: add this test, check for correct setting of NameScope
6868
//TestHelperLog.Log("ExampleDependencyObject.OnPropertyChanged " + e.Property.Name);
6969
}
70+
71+
public static readonly DependencyProperty ExampleProperty = DependencyProperty.RegisterAttached(
72+
"Example", typeof(string), typeof(ExampleDependencyObject)
73+
);
74+
75+
public static string GetExample(DependencyObject element)
76+
{
77+
TestHelperLog.Log("ExampleDependencyObject.GetExample");
78+
return (string)element.GetValue(ExampleProperty);
79+
}
80+
81+
public static void SetExample(DependencyObject element, string value)
82+
{
83+
TestHelperLog.Log("ExampleDependencyObject.SetExample");
84+
element.SetValue(ExampleProperty, value);
85+
}
86+
}
87+
88+
public class DerivedExampleDependencyObject : ExampleDependencyObject
89+
{
7090
}
7191
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,5 +418,18 @@ public void ExampleClassObjectPropWithExplicitMarkupExtension2()
418418
</t:ExampleClass>
419419
");
420420
}
421+
422+
[Test]
423+
public void UsingAttachedPropertyOnDerivedClass()
424+
{
425+
TestLoading(@"
426+
<Window
427+
xmlns=""http://schemas.microsoft.com/netfx/2007/xaml/presentation""
428+
xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @"""
429+
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
430+
t:DerivedExampleDependencyObject.Example=""test"">
431+
</Window>
432+
");
433+
}
421434
}
422435
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,11 @@ internal static XamlPropertyInfo TryFindAttachedProperty(Type elementType, strin
478478
return new XamlDependencyPropertyInfo((DependencyProperty)field.GetValue(null), true);
479479
}
480480
}
481+
482+
if (elementType.BaseType != null) {
483+
return TryFindAttachedProperty(elementType.BaseType, propertyName);
484+
}
485+
481486
return null;
482487
}
483488

0 commit comments

Comments
 (0)