c# - wpf scrollviewer mousewheel not working with stackpanel -


i have stackpanel wrapped scrollviewer. inside stackpanel i've grids , inside grids there're stackpanels again , tiles control mahapps metro.

the scrollviewer working fine if drag scrollbar. mousewheel not working. may control stealing mousewheel action can't feagure out one. i've tried scroll mouse wheel while focusing on scrollbar. it's still not working.

<scrollviewer x:name="ts" grid.row="1" horizontalalignment="stretch" horizontalscrollbarvisibility="auto" verticalscrollbarvisibility="disabled" cancontentscroll="true" panningmode="horizontalonly" snapstodevicepixels="true" background="transparent">     <stackpanel x:name="tilespanel" verticalalignment="top" horizontalalignment="stretch" orientation="horizontal">         <stackpanel.resources>             <style targettype="{x:type grid}">                 <setter property="margin" value="0,50,0,0"/>             </style>         </stackpanel.resources>         <separator background="{x:null}" width="110"></separator>         <grid>             <stackpanel>                 <stackpanel orientation="horizontal">                     <stackpanel.resources>                         <style targettype="{x:type grid}">                             <setter property="margin" value="10,0,0,0"/>                         </style>                     </stackpanel.resources>                     <grid height="260">                         <stackpanel>                             <stackpanel.resources>                                 <style targettype="{x:type stackpanel}">                                     <setter property="margin" value="0,0,0,10"/>                                 </style>                             </stackpanel.resources>                         <stackpanel width="247" height="119">                             <custom:tile x:name="mail" margin="0" width="auto" d:layoutoverrides="height">                                 <image stretch="fill" source="res/apptiles/mail.png"/>                             </custom:tile>                         </stackpanel>                          //and goes on this//                          </grid>                       </stackpanel>                 <separator background="{x:null}" width="50"/>             </grid>     </stackpanel>     </scrollviewer> 

is grid that's coming in way? or there other way use mousewheel in horizontal scrollviewer? can't figure out. please help.

usually mouse have 1 scroll wheel assigned vertical scroll. assume same case.

based on code seems want perform horizontal scroll mouse wheel.

i propose solution using attached properties

sample xaml

<scrollviewer x:name="ts"               grid.row="1"               horizontalalignment="stretch"               horizontalscrollbarvisibility="auto"               verticalscrollbarvisibility="disabled"               cancontentscroll="false"               panningmode="horizontalonly"               snapstodevicepixels="true"               background="transparent"               l:scrollviewerextensions.ishorizontalscrollonwheelenabled="true"> 

i have attached scrollviewerextensions.ishorizontalscrollonwheelenabled scroll viewer enable horizontal scrolling via mouse wheel. remember set cancontentscroll="false", needed in case.

scrollviewerextensions class

namespace csharpwpf {     class scrollviewerextensions : dependencyobject     {         public static bool getishorizontalscrollonwheelenabled(dependencyobject obj)         {             return (bool)obj.getvalue(ishorizontalscrollonwheelenabledproperty);         }          public static void setishorizontalscrollonwheelenabled(dependencyobject obj, bool value)         {             obj.setvalue(ishorizontalscrollonwheelenabledproperty, value);         }          // using dependencyproperty backing store ishorizontalscrollonwheelenabled.  enables animation, styling, binding, etc...         public static readonly dependencyproperty ishorizontalscrollonwheelenabledproperty =             dependencyproperty.registerattached("ishorizontalscrollonwheelenabled", typeof(bool), typeof(scrollviewerextensions), new propertymetadata(false, onishorizontalscrollonwheelenabledchanged));          private static void onishorizontalscrollonwheelenabledchanged(dependencyobject d, dependencypropertychangedeventargs e)         {             scrollviewer sv = d scrollviewer;             if ((bool)e.newvalue)                 sv.previewmousewheel += sv_previewmousewheel;             else                 sv.previewmousewheel -= sv_previewmousewheel;         }          static void sv_previewmousewheel(object sender, mousewheeleventargs e)         {             scrollviewer scrollviewer = sender scrollviewer;             if (e.delta > 0)                 scrollviewer.lineleft();             else                 scrollviewer.lineright();             e.handled = true;         }     } } 

whole idea listen mouse wheel , scroll left or right based on wheel delta (rotation)


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -