c# - How to reuse WPF styles? -


i have style i'm using on several columns of datagrid.

<datagridtextcolumn ...>   <datagridtextcolumn.editingelementstyle>     <style targettype="textbox">       <setter .../>       <setter .../>    </style>   </datagridtextcolumn.editingelementstyle> </datagridtextcolumn> 

i'm replicating above style code columns. there way without replicating code?

put in resourcedictionary or parent control's(the window or datagrid) resources:

<style x:key="textcolumneditstyle" targettype="textbox">     <setter .../>     <setter .../> </style> 

and can reuse this:

<datagrid>     <datagridtextcolumn editingelementstyle="{staticresource textcolumneditstyle}"></datagridtextcolumn>     <datagridtextcolumn editingelementstyle="{staticresource textcolumneditstyle}"></datagridtextcolumn> </datagrid> 

Comments