WPF DataGrid DataGridRow Selection Border and Spacing -


i'm using wpf datagrid display data , when user selects row, i'd background of entire row highlighted (with gradient) , have border. i've been using following code, works part:

    <style targettype="datagridrow">         <setter property="borderbrush" value="transparent" />         <setter property="borderthickness" value="0" />     <style.triggers>         <datatrigger binding="{binding ischecked}" value="true">             <setter property="borderthickness" value="1"/>             <setter property="borderbrush" value="{staticresource bordercolor}" />             <setter property="background" value="{staticresource backgroundcolor}" />         </datatrigger>     </style.triggers>     </style> 

this issue i'm having border. if borderthickness set 0, entire row "shifts over" make space border when datatrigger triggered. if set borderthickness 1 initially, highlighted row displayed correctly, there empty border around row when it's in it's default state, causing row gridlines not touch edge.

any ideas on how work around this?

i've found tweaking visuals easier listbox instead of datagrid maybe 1 way go.

try starting point:

<listbox>     <listbox.itemcontainerstyle>         <style targettype="{x:type listboxitem}">             <style.triggers>                 <datatrigger binding="{binding ischecked}" value="true">                     <setter property="borderbrush" value="{staticresource bordercolor}" />                     <setter property="background" value="{staticresource backgroundcolor}" />                 </datatrigger>             </style.triggers>             <setter property="background" value="transparent" />             <setter property="borderbrush" value="transparent" />         </style>     </listbox.itemcontainerstyle>     <listbox.itemtemplate>         <datatemplate datatype="{x:type local:myclass}">             <grid>                 <grid.columndefinitions>                     <columndefinition width="30" />                     <columndefinition width="*" />                 </grid.columndefinitions>                 <checkbox ischecked="{binding ischecked}" />                 <textblock text="{binding mytextproperty}" grid.column="1" />             </grid>         </datatemplate>     </listbox.itemtemplate> </listbox> 

this should set correct border , background without moving elements of selected row or showing surrounding gaps unselected ones. replace local:myclass class , customize grid contents scenario.

see this answer on how deal mouseover/selected styles, tried copying template property setter example above , adjusting panel.background , border.borderbrush setters seems work well.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -