Move Image control in VB2010 WPF
In windows forms, you can easily change the ".left" value of a picturebox to move it. However, I have noticed that in VB2010 WPF, this is not the case.. Can anyone show me how to change an image control's .left (or equivalent) value in w开发者_如何学Gopf? Thanks
Nick
Normally placement in WPF depends on the container a control is a child of. If you want to adjust placements you can either use the Margin
property which should work for almost all containers or place the Image in a Canvas
, then you can use the Canvas.Left
attached property for placement.
Additionally you could use LayoutTransform
or RenderTransform
properties to move your control around; you would use a TranslateTransform
for that.
e.g.
<Grid>
<Button Margin="20,0,0,0" Content="Using Margin"/>
</Grid>
<Canvas Height="30">
<Button Canvas.Left="20" Content="Using a Canvas"/>
</Canvas>
<Grid>
<Button Content="Using TranslateTransform">
<Button.RenderTransform>
<TranslateTransform X="20"/>
</Button.RenderTransform>
</Button>
</Grid>
(Changing margin programmatically:)
Thickness margin = Control.Margin;
margin.Left += 1;
Control.Margin = margin;
精彩评论