c# - Set image position on canvas programatically -
i have following code:
namespace game { public partial class mainwindow : window { image img = new image(); public mainwindow() { initializecomponent(); mycanvas.focus(); img.source = new bitmapimage(new uri("c:\\users\\public\\pictures\\sample pictures\\koala.jpg")); img.width = 100; img.height = 100; } public void onkeydownhandler(object sender, keyeventargs e) { canvas.settop(img, 0); canvas.setleft(img, 0); this.content = img; } } }
and xaml:
<canvas name="mycanvas" keydown="onkeydownhandler" focusable="true" horizontalalignment="left" height="166" margin="118,89,0,0" verticalalignment="top" width="300"/>
when press button, image shown, want do, in center of window. want set image on x,y position want. how do that?
<canvas> <image x:name="foo" canvas.top="200" canvas.left="200" /> </canvas> foo.setvalue(canvas.left, 100); foo.setvalue(canvas.top, 225);
this basic test scenario. sets image image.setvalue(canvas.position, int)
says so.
Comments
Post a Comment