c# - Textblock as Link conditionally -
i have label text property bound class:
<textblock visibility="hidden" texttrimming="wordellipsis" grid.row="0" grid.column="0" verticalalignment="center" text="{binding displaytext}" textwrapping="wrap" fontsize="10"></textblock>
if displaytext
link hyperlink should used. class binding provides uri
, boolean islink
. tried putting hyperlink
element inside of textblock
, set navigateuri
uri
class did not work me. have clean solution this?
i think can bind template according property.
<contentcontrol> <contentcontrol.style> <style targettype="contentcontrol"> <style.triggers> <datatrigger binding="{binding islink}" value="true"> <setter property="contenttemplate" > <setter.value> <datatemplate> <textblock> <hyperlink navigateuri="{binding datacontext.url, relativesource={relativesource mode=findancestor, ancestortype= contentcontrol} }"> <textblock text="{binding datacontext.displaytext, relativesource={relativesource mode=findancestor, ancestortype=contentcontrol} }"/> </hyperlink> </textblock> </datatemplate> </setter.value> </setter> </datatrigger> <datatrigger binding="{binding islink}" value="false"> <setter property="contenttemplate" > <setter.value> <datatemplate> <textblock text="{binding datacontext.displaytext,relativesource={relativesource mode=findancestor, ancestortype=contentcontrol} }"/> </datatemplate> </setter.value> </setter> </datatrigger> </style.triggers> </style> </contentcontrol.style> </contentcontrol>
Comments
Post a Comment