c# - Scrolable Canvas with movable items inside ScrollViewer -


i've got scrollviewer contains canvas. there movable uielements @ canvas. here xaml code:

<scrollviewer x:name="scroller" horizontalscrollbarvisibility="auto" background="white">        <canvas x:name="mapcanvas" width="4000" height="4000">                         <button x:name="testbtn"                              content="my button"                             canvas.left="250"                             manipulationstarted="mapitem_manipulationstarted"                                manipulationdelta="mapitem_manipulationdelta"                              manipulationcompleted="mapitem_manipulationcompleted"                                />                                         </canvas> </scrollviewer> 

here code of event handlers:

private void mapitem_manipulationdelta(object sender, system.windows.input.manipulationdeltaeventargs e)         {             frameworkelement btn = sender frameworkelement;             if (null == btn) return;                          double left = canvas.getleft(btn) + e.deltamanipulation.translation.x;             double top = canvas.gettop(btn) + e.deltamanipulation.translation.y;              if (left < 0)                 left = 0;             else if (left >  mapcanvas.actualwidth - btn.actualwidth)                 left = mapcanvas.actualwidth - btn.actualwidth;              if (top < 0)                 top = 0;             else if(top > mapcanvas.actualheight - btn.actualheight)                 top = mapcanvas.actualheight - btn.actualheight;              canvas.setleft(btn, left);             canvas.settop(btn, top);              e.handled = true;         }          private void mapitem_manipulationcompleted(object sender, system.windows.input.manipulationcompletedeventargs e)         {             scroller.horizontalscrollbarvisibility = scrollbarvisibility.auto;             scroller.verticalscrollbarvisibility = scrollbarvisibility.auto;                          e.handled = true;         }          private void mapitem_manipulationstarted(object sender, system.windows.input.manipulationstartedeventargs e)         {             scroller.horizontalscrollbarvisibility = scrollbarvisibility.disabled;             scroller.verticalscrollbarvisibility = scrollbarvisibility.disabled;              e.handled = true;         } 

everything works perfect. when scrollviewer has scrolled horizontaloffset or verticaloffset , i'm clicking or tapping uielement in visible area seems scrollviewer automatically scrolls horisontaloffset == 0 , verticaloffset == 0. then, after releasing uielement, jumps back. how can avoid behavior , make scrollviewer stay @ it's place while i'll dragging uielement placed canvas inside it?

i haven't tested this, try replacing (or adding to) calls disable/re-enable scrollbar visibility calls disable/re-enable scrollviewer control itself:

private void mapitem_manipulationstarted(object sender, manipulationstartedeventargs e) {     scroller.isenabled = false; }  private void mapitem_manipulationcompleted(object sender, manipulationcompletedeventargs e) {     scroller.isenabled = true; } 

if work, may affect style when becomes disabled, may have re-style using trigger on isenabled property when equals false.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -