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

Commit 6c8f77f

Browse files
author
gumme
committed
Removed sealed constraint from class declaration to allow inheritance.
Performs casting of extended component only once in OnInitialized, and casts to only necessary level (i.e. FrameworkElement) to allow inherited classes to support other panels that maps to Canvas placement properties (using DependencyProperty.AddOwner).
1 parent ef49522 commit 6c8f77f

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

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
{

0 commit comments

Comments
 (0)