c# - WPF Resource section not effecting my Label control in the view -


i have created style “required field” label should place red asterisk “*” in front of label. here xaml taken application.resources section of wpf application:

    <style targettype="label" x:key="requiredfield">         <setter property="margin" value="0,0,5,0" />         <setter property="horizontalalignment" value="right" />         <setter property="content">             <setter.value>                 <controltemplate>                     <stackpanel orientation="horizontal">                         <textblock text="*" foreground="red" fontsize="10"/>                         <textblock text="{binding}" />                     </stackpanel>                 </controltemplate>             </setter.value>          </setter>     </style> 

the xaml in view uses resource this:

<label grid.row="1" grid.column="0" style="{staticresource requiredfield}" content="name:"/> 

annoyingly doesn’t appear modify label. can tell me i’ve done wrong?

well style seems wrong. try way.

<style targettype="label" x:key="requiredfield">     <setter property="margin" value="0,0,5,0" />     <setter property="horizontalalignment" value="right" />     <setter property="template">         <setter.value>             <controltemplate targettype="{x:type label}">                 <stackpanel orientation="horizontal">                     <textblock text="*" foreground="red" fontsize="10"/>                     <textblock text="{templatebinding content}" />                 </stackpanel>             </controltemplate>         </setter.value>      </setter> </style> 

this should trick, it's totally untested.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -