wpf DataGrid Scroll with mouseclick scrollBar Error when Row Drag and Drop -
i wrote dodragdrop in datagrid.
however, can't click , drag scroll bar on datagrid because drag error occurred.
but can scroll mouse wheel.
how can fix it? here part of code.
.cs file
private void datagrid_mousemove(object sender, mouseeventargs e) { if (e.leftbutton == mousebuttonstate.pressed) { point currentposition = e.getposition(incidentlist); object selecteditem = datagrid.selecteditem; if (selecteditem != null) { datagridrow container = (datagridrow)datagrid.itemcontainergenerator.containerfromitem(selecteditem); var dataobj = new dataobject(); dataobj.setdata("dragsource", container); if (container != null) { dragdrop.dodragdrop(container, dataobj, dragdropeffects.copy); } } } }
.xaml file
<datagrid x:name="datagrid" columnheaderstyle="{staticresource mycolumnheader}" style="{dynamicresource datagridstyle}" canuseraddrows="false" verticalalignment="stretch" height="{binding relativesource={relativesource findancestor, ancestortype={x:type grid}}, path=actualheight}" horizontalalignment="stretch" minheight="150" selectionmode="single" itemssource="{binding mylistdata, updatesourcetrigger=propertychanged}" autogeneratecolumns="false" selecteditem="{binding selectmyrow}" mousemove="datagrid_mousemove"> .....
register handler on row instead of datagrid:
<datagrid> <datagrid.rowstyle> <style targettype="datagridrow"> <eventsetter event="mousemove" handler="rowmovehandler"/> </style> </datagrid.rowstyle>
and take sender-row container:
private void rowmovehandler(object sender, mouseeventargs e) { var container = sender datagridrow; if (container != null && e.leftbutton == mousebuttonstate.pressed) { var dataobj = new dataobject(); dataobj.setdata("dragsource", container); dragdrop.dodragdrop(container, dataobj, dragdropeffects.copy); } }
Comments
Post a Comment