Differences between Canvas Property and Margin

Are there any differences between using SetValuewith (for example) Canvas.LeftPropertyand MarginProperty?

To be more clear:

<Canvas>
   <Rectangle x:Name="rect">                         
</Canvas>

there is

rect.SetValue(Canvas.LeftProperty, 10)

equivalently

rect.Margin = new Thickness(10, 0, 0, 0)

or not?

+5
source share
5 answers

The Margin property is used with each element to determine the additional space around the object. It works in almost all types of layouts (StackPanel, Grid, ContentControls, etc.).

Canvas.LeftProperty( Top, Right Bottom) , Canvas. Canvas , , . Shape, Path, Canvas Shape .

, , Canvas, Shape ( ), . 3 . .

, Rectangle Width Height, Canvas.Left Canvas.Top. , Canvas.Left Canvas.Top. margin Canvas, , .

+4

, rect 10. rect 10.

.

EDIT: WPF. rect ArrangeOverride Canvas ArrangeOverride .

+1

Canvas . .

Rectangle , , . X Canvas.Left Margin.Left.

, 10 + 0, 0 + 10.

, . Canvas.Left , , , .

+1
Canvas.Left
Canvas.Right
Canvas.Top
Canvas.Bottom

canvas, , . (left = 10, right = 10 , 10 )

Margin.Left
Margin.Right
Margin.Top
Margin.Bottom

, , Canvas , , ( - NaN).

0

Margin TemplateBinding , DependencyProperty. .

Canvas properties are tied to FrameworkElement properties and allow you to position elements that may not have Margin properties. And they do not work if the object does not have a Canvas parent.

0
source

All Articles