c# - how to move a button in WPF -
xaml code below
<window x:class="denemewpfapplication1.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525"> <grid> <dockpanel width="auto" verticalalignment="stretch" height="auto" horizontalalignment="stretch" grid.columnspan="1" grid.column="0" grid.row="0" margin="0,0,0,0" grid.rowspan="1"> <stackpanel> <stackpanel.background> <lineargradientbrush> <gradientstop color="white" offset="0" /> <gradientstop color="darkkhaki" offset=".3" /> <gradientstop color="darkkhaki" offset=".7" /> <gradientstop color="white" offset="1" /> </lineargradientbrush> </stackpanel.background> <stackpanel margin="10"> <button name="simplebutton" click="simplebuttonclick" keydown="simplebutton_keydown">simple</button> <button name="cubebutton" click="cubebuttonclick">cube</button> </stackpanel> </stackpanel> <viewport3d name="mainviewport" cliptobounds="true"> <viewport3d.camera> <perspectivecamera farplanedistance="100" lookdirection="-11,-10,-9" updirection="0,1,0" nearplanedistance="1" position="11,10,9" fieldofview="70" /> </viewport3d.camera> <modelvisual3d> <modelvisual3d.content> <directionallight color="white" direction="-2,-3,-1" /> </modelvisual3d.content> </modelvisual3d> </viewport3d> </dockpanel> </grid> </window>
this inide xaml.cs
private void simplebutton_keydown(object sender, keyeventargs e) { if (e.key == key.p) { //something move simplebutton } }
i want move simplebutton
when p pressed keyboard, can't seem find method or way that.
if animation not required
if (e.key == key.p) { cubebutton.margin = new thickness(60, 50, 50, 60); }
left,top,right,bottom should numbers
and have added keydown
event
button button must focused in order receive keydown
event
also @ translatetransform in wpf
Comments
Post a Comment