0

Here is my code :

                    <Image x:Name="Layer_22_copy" Height="542" Canvas.Left="16" Opacity="0.522" Source="gammon2_Images\Layer 22 copy.png" Canvas.Top="13" Width="315"/>

how can i change position of this image on Code Behind? i am new in WPF. thank you.

Shahin
  • 12,543
  • 39
  • 127
  • 205
  • i want of move it on board (its backgammon game) i converted psd style to XAML. – Shahin Aug 18 '10 at 14:20
  • 1
    Check here to see if this will help. It will help you find your control and then you should be able to move the Top and Left fields to move the Image. You could probably cast it as an image or button. – XstreamINsanity Aug 18 '10 at 14:21
  • 1
    @xstreaminsanity He doesn't need to do anything complicated to find the control - it has a name – Martin Harris Aug 18 '10 at 14:22

2 Answers2

2
Layer_22_copy.SetValue(Canvas.TopProperty, newTopValue);
Layer_22_copy.SetValue(Canvas.LeftProperty, newLeftValue);
Martin Harris
  • 28,277
  • 7
  • 90
  • 101
1

You can set the Margin Property like

Layer_22_copy.Margin = new Thickness(10, 30, 0, 0);
Prince Ashitaka
  • 8,623
  • 12
  • 48
  • 71
  • what's deference between margin and canvas.left and right property? – Shahin Aug 18 '10 at 18:21
  • 1
    No big difference. If, you hosted the image inside a canvas you could use the Canvas.Left or Top or Right or Bottom. But, you can set margin even if you hosted it in Grid or in any custom panel. Also, It will reduce the number of lines. :) – Prince Ashitaka Aug 18 '10 at 18:43
  • There's a difference when it comes to layout and where things actually are, but that only matters if you're trying to figure out offsets between controls and things like that. – Lee Louviere Jul 26 '12 at 17:38