c# - How to get row selection working with DataGrid using XAML only databinding -


i have following datagrid definition

 <datagrid     virtualizingpanel.virtualizationmode="recycling"     canuseraddrows="false"     canuserdeleterows="false"     selectionmode="single"     itemssource="{binding          toolpath.toolpath,          mode=oneway,         converter={staticresource indexedconverter}}"      autogeneratecolumns="false"      selectedindex="{binding selectedindex, mode=twoway}"> 

i'm using mvvm , have view model selectedindex property implementing inpc. i've used snoop verify selectedindex on datagrid changes when in view model. row of grid not selected or highlighted when so.

enter image description here

as can see row not highlighted think can detect little 3 pixel wide widget left of row darker blue.

is there xaml only way via databinding ( without writing code behind ) row selection working?

can't seem figure out way xaml. hacking , reading posts best can come is.

<datagrid     x:name="toolpathgridview"     virtualizingpanel.virtualizationmode="recycling"     canuseraddrows="false"     selectionunit="fullrow"     canuserdeleterows="false"     selectionmode="single"     loaded="toolpathgridview_loaded"     itemssource="{binding          toolpath.toolpath,          mode=oneway,         converter={staticresource indexedconverter}}"      autogeneratecolumns="false"      selectedindex="{binding selectedindex, mode=twoway}"> 

and

private void toolpathgridview_loaded( object sender, routedeventargs e ) {     toolpathgridview.itemcontainergenerator.statuschanged += new eventhandler(itemcontainergenerator_statuschanged); }  void itemcontainergenerator_statuschanged( object sender, eventargs e ) {     if ( toolpathgridview.itemcontainergenerator.status == generatorstatus.containersgenerated )     {         int = 0;         if ( viewmodel!=null )         {             = viewmodel.selectedindex;         }         toolpathgridview.selectedindex = 0;         datagridrow r = toolpathgridview.itemcontainergenerator.containerfromindex(0) datagridrow;         if ( r != null )         {             r.isselected = false;             r.isselected = true;         }     } } 

so happening here. trick seems have wait till datagrid has built it's internal container model. when done can pick off row , mark selected. if try there no rows.

this should property of grid itself.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -