c# - How to change background color of stack panel when selected in datagrid -


i have change background color of stackpanel (present in datagrid) when selected or focused.

below xaml:

<datagrid background="#dce1e7" selecteditem="{binding row, mode=twoway}"  autogeneratecolumns="false" canuseraddrows="false" headersvisibility="none"  gridlinesvisibility="none" horizontalalignment="left" borderthickness="0" name="dtlcuisine" verticalalignment="top" borderbrush="#dce1e7" verticalgridlinesbrush="#dce1e7" horizontalgridlinesbrush="#dce1e7"   columnwidth="130" selectionchanged="dtlcuisine_selectionchanged" celleditending="dtlcuisine_celleditending">     <datagrid.columns>         <datagridtemplatecolumn x:name="template13">             <datagridtemplatecolumn.celltemplate>                 <datatemplate>                     <stackpanel name="stkpnlcuisines" orientation="horizontal" background="#dce1e7" margin="-1,-1,-1,-1" mousedown="stkpnlcuisines_mousedown_1">                         <label content="{binding cuisinename}" height="28" horizontalalignment="left" name="lblcuisinename" verticalalignment="top" fontsize="14" />                         <stackpanel.style>                             <style targettype="{x:type stackpanel}">                                 <style.triggers>                                     <datatrigger binding="{binding relativesource={relativesource self}, path=isfocused}" value="true">                                         <setter property="background" value="red" />                                     </datatrigger>                                 </style.triggers>                             </style>                         </stackpanel.style>                     </stackpanel>                 </datatemplate>             </datagridtemplatecolumn.celltemplate>              <datagridtemplatecolumn.celleditingtemplate>                 <datatemplate>                     <stackpanel margin="-1,-1,-1,-1">                         <textbox name="txtcuisinecategory" acceptsreturn="true" text="{binding cuisinename}" lostfocus="txtcuisinecategory_lostfocus" />                     </stackpanel>                 </datatemplate>             </datagridtemplatecolumn.celleditingtemplate>         </datagridtemplatecolumn>     </datagrid.columns> </datagrid> 

what best way change background color of stackpanel.

use isselected trigger on datagridcell. if wan't change selected colors accross elements, can use following code in application resources.

<solidcolorbrush x:key="{x:static systemcolors.highlightbrushkey}" color="#3271b5" /> <solidcolorbrush x:key="{x:static systemcolors.highlighttextbrushkey}" color="aliceblue" /> 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -