Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// Provides <see cref="IPlacementBehavior"/> behavior for <see cref="Canvas"/>.
/// </summary>
[ExtensionFor(typeof(Canvas), OverrideExtension=typeof(DefaultPlacementBehavior))]
public sealed class CanvasPlacementSupport : SnaplinePlacementBehavior
public class CanvasPlacementSupport : SnaplinePlacementBehavior
{
GrayOutDesignerExceptActiveArea grayOut;
FrameworkElement extendedComponent;
FrameworkElement extendedView;

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

protected override void OnInitialized()
{
base.OnInitialized();

extendedComponent = (FrameworkElement)ExtendedItem.Component;
extendedView = (FrameworkElement)this.ExtendedItem.View;
}

public override void SetPosition(PlacementInformation info)
{
base.SetPosition(info);
Expand All @@ -58,7 +68,7 @@ public override void SetPosition(PlacementInformation info)

if (IsPropertySet(child, Canvas.RightProperty))
{
var newR = ((Canvas) ExtendedItem.Component).ActualWidth - newPosition.Right;
var newR = extendedComponent.ActualWidth - newPosition.Right;
if (newR != GetCanvasProperty(child, Canvas.RightProperty))
info.Item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(newR);
}
Expand All @@ -70,7 +80,7 @@ public override void SetPosition(PlacementInformation info)

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

if (info.Item == Services.Selection.PrimarySelection)
{
var cv = this.ExtendedItem.View as Canvas;
var b = new Rect(0, 0, cv.ActualWidth, cv.ActualHeight);
var b = new Rect(0, 0, extendedView.ActualWidth, extendedView.ActualHeight);
// only for primary selection:
if (grayOut != null)
{
Expand Down