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

Commit 8cc570d

Browse files
committed
Merge remote-tracking branch 'remotes/sd/master'
2 parents 35c2af4 + fadbc15 commit 8cc570d

25 files changed

Lines changed: 561 additions & 6 deletions

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
3030
/// Provides <see cref="IPlacementBehavior"/> behavior for <see cref="Canvas"/>.
3131
/// </summary>
3232
[ExtensionFor(typeof(Canvas), OverrideExtension=typeof(DefaultPlacementBehavior))]
33-
public sealed class CanvasPlacementSupport : SnaplinePlacementBehavior
33+
public class CanvasPlacementSupport : SnaplinePlacementBehavior
3434
{
3535
GrayOutDesignerExceptActiveArea grayOut;
36+
FrameworkElement extendedComponent;
37+
FrameworkElement extendedView;
3638

3739
static double GetCanvasProperty(UIElement element, DependencyProperty d)
3840
{
@@ -48,6 +50,14 @@ static bool IsPropertySet(UIElement element, DependencyProperty d)
4850
return element.ReadLocalValue(d) != DependencyProperty.UnsetValue;
4951
}
5052

53+
protected override void OnInitialized()
54+
{
55+
base.OnInitialized();
56+
57+
extendedComponent = (FrameworkElement)ExtendedItem.Component;
58+
extendedView = (FrameworkElement)this.ExtendedItem.View;
59+
}
60+
5161
public override void SetPosition(PlacementInformation info)
5262
{
5363
base.SetPosition(info);
@@ -58,7 +68,7 @@ public override void SetPosition(PlacementInformation info)
5868

5969
if (IsPropertySet(child, Canvas.RightProperty))
6070
{
61-
var newR = ((Canvas) ExtendedItem.Component).ActualWidth - newPosition.Right;
71+
var newR = extendedComponent.ActualWidth - newPosition.Right;
6272
if (newR != GetCanvasProperty(child, Canvas.RightProperty))
6373
info.Item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(newR);
6474
}
@@ -70,7 +80,7 @@ public override void SetPosition(PlacementInformation info)
7080

7181
if (IsPropertySet(child, Canvas.BottomProperty))
7282
{
73-
var newB = ((Canvas)ExtendedItem.Component).ActualHeight - newPosition.Bottom;
83+
var newB = extendedComponent.ActualHeight - newPosition.Bottom;
7484
if (newB != GetCanvasProperty(child, Canvas.BottomProperty))
7585
info.Item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(newB);
7686
}
@@ -81,8 +91,7 @@ public override void SetPosition(PlacementInformation info)
8191

8292
if (info.Item == Services.Selection.PrimarySelection)
8393
{
84-
var cv = this.ExtendedItem.View as Canvas;
85-
var b = new Rect(0, 0, cv.ActualWidth, cv.ActualHeight);
94+
var b = new Rect(0, 0, extendedView.ActualWidth, extendedView.ActualHeight);
8695
// only for primary selection:
8796
if (grayOut != null)
8897
{

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/DragTreeViewItem.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
159159
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
160160
{
161161
base.OnMouseLeftButtonUp(e);
162-
ParentTree.ItemMouseUp(this);
162+
163+
if (ParentTree != null) {
164+
ParentTree.ItemMouseUp(this);
165+
}
163166
}
164167
}
165168
}

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

-9 KB
Binary file not shown.
-15 KB
Binary file not shown.
-76 KB
Binary file not shown.
-596 KB
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.30324.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PackagePrepApp", "PackagePrepApp\PackagePrepApp.csproj", "{6788F8CB-B7C4-4787-9D46-CAAB16F1E9DA}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{6788F8CB-B7C4-4787-9D46-CAAB16F1E9DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{6788F8CB-B7C4-4787-9D46-CAAB16F1E9DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{6788F8CB-B7C4-4787-9D46-CAAB16F1E9DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{6788F8CB-B7C4-4787-9D46-CAAB16F1E9DA}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

0 commit comments

Comments
 (0)