Browse Source

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).
pull/443/head
gumme 12 years ago
parent
commit
6c8f77f4b1
  1. 19
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs

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

@ -30,9 +30,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// Provides <see cref="IPlacementBehavior"/> behavior for <see cref="Canvas"/>. /// Provides <see cref="IPlacementBehavior"/> behavior for <see cref="Canvas"/>.
/// </summary> /// </summary>
[ExtensionFor(typeof(Canvas), OverrideExtension=typeof(DefaultPlacementBehavior))] [ExtensionFor(typeof(Canvas), OverrideExtension=typeof(DefaultPlacementBehavior))]
public sealed class CanvasPlacementSupport : SnaplinePlacementBehavior public class CanvasPlacementSupport : SnaplinePlacementBehavior
{ {
GrayOutDesignerExceptActiveArea grayOut; GrayOutDesignerExceptActiveArea grayOut;
FrameworkElement extendedComponent;
FrameworkElement extendedView;
static double GetCanvasProperty(UIElement element, DependencyProperty d) static double GetCanvasProperty(UIElement element, DependencyProperty d)
{ {
@ -48,6 +50,14 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
return element.ReadLocalValue(d) != DependencyProperty.UnsetValue; 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) public override void SetPosition(PlacementInformation info)
{ {
base.SetPosition(info); base.SetPosition(info);
@ -58,7 +68,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (IsPropertySet(child, Canvas.RightProperty)) 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)) if (newR != GetCanvasProperty(child, Canvas.RightProperty))
info.Item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(newR); info.Item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(newR);
} }
@ -70,7 +80,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (IsPropertySet(child, Canvas.BottomProperty)) 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)) if (newB != GetCanvasProperty(child, Canvas.BottomProperty))
info.Item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(newB); info.Item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(newB);
} }
@ -81,8 +91,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (info.Item == Services.Selection.PrimarySelection) if (info.Item == Services.Selection.PrimarySelection)
{ {
var cv = this.ExtendedItem.View as Canvas; var b = new Rect(0, 0, extendedView.ActualWidth, extendedView.ActualHeight);
var b = new Rect(0, 0, cv.ActualWidth, cv.ActualHeight);
// only for primary selection: // only for primary selection:
if (grayOut != null) if (grayOut != null)
{ {

Loading…
Cancel
Save