@@ -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