Friday, 15 August 2014

c# - Why control doesn't pick up the generic style defined for the controls of it's type -



c# - Why control doesn't pick up the generic style defined for the controls of it's type -

i trying apply next style borders in form:

<usercontrol.resources> <style targettype="{x:type border}"> <setter property="borderbrush" value="#5076a7" /> <setter property="borderthickness" value="1" /> <setter property="cornerradius" value="4" /> </style> <style ... /> <usercontrol.resources>

however border within listview , non of other borders pick style unless utilize x:key foosyle value , refer key in <boder style={staticresource foostyle}> if sure not want do.

the border mentioned below:

<listview.itemcontainerstyle> <style targettype="{x:type listviewitem}"> <style.setters> <setter property="template"> <setter.value> <controltemplate targettype="{x:type listviewitem}"> <border> <grid margin="2"> <grid.rowdefinitions> <rowdefinition height="auto"/> <rowdefinition height="auto"/> <rowdefinition height="auto"/> <rowdefinition height="auto"/> <rowdefinition height="auto"/> </grid.rowdefinitions> ...

what missing here?

i've written 2 style code problem.you can utilize style.resources or controltemplate.resources.also,you have found right solution

here code: (using dynamicresource)

<window.resources> <style x:key="listviewitemborderstyle" targettype="{x:type border}"> <setter property="background" value="red"/> <setter property="borderbrush" value="#5076a7" /> <setter property="borderthickness" value="1" /> <setter property="cornerradius" value="4" /> </style> </window.resources> <listview> <listviewitem content="asdasd"/> <listviewitem content="asdasd"/> <listviewitem content="asdasd"/> <listview.itemcontainerstyle> <style targettype="{x:type listviewitem}"> <style.setters> <setter property="template"> <setter.value> <controltemplate targettype="{x:type listviewitem}"> <border height="100" style="{dynamicresource listviewitemborderstyle}"> <!--....--> </border> </controltemplate> </setter.value> </setter> </style.setters> </style> </listview.itemcontainerstyle> </listview>

another 1 code( using staticresource).it's embedded in controltemplate

<listview> <listviewitem content="asdasd"/> <listviewitem content="asdasd"/> <listviewitem content="asdasd"/> <listview.itemcontainerstyle> <style targettype="{x:type listviewitem}"> <style.setters> <setter property="template"> <setter.value> <controltemplate targettype="{x:type listviewitem}"> <controltemplate.resources> <style x:key="listviewitemborderstyle" targettype="{x:type border}"> <setter property="background" value="red"/> <setter property="borderbrush" value="#5076a7" /> <setter property="borderthickness" value="1" /> <setter property="cornerradius" value="4" /> </style> </controltemplate.resources> <border height="100" style="{dynamicresource listviewitemborderstyle}"> <!--....--> </border> </controltemplate> </setter.value> </setter> </style.setters> </style> </listview.itemcontainerstyle> </listview>

c# wpf xaml styles wpf-style

No comments:

Post a Comment