windows phone 7 - How to add the click event on textblock of listbox? -


i developing window phone 7 application. have listbox in application. doing dynamic binding listbox. code of listbox follows:

<listbox x:name="firstlistbox" margin="0,0,-12,0" itemssource="{binding items}" >     <listbox.itemtemplate>         <datatemplate>             <stackpanel margin="0,0,0,17" width="432">                 <textblock  text="{binding id}" width="440"></textblock>                 <textblock text="{binding iscompany}" width="440"></textblock>                                                                                        <textblock foreground="red" text="{binding companyorindividual}" width="440"></textblock>                                                                                             <textblock  text="{binding microsoftcontact}" width="440"></textblock>             </stackpanel>         </datatemplate>     </listbox.itemtemplate>     <listbox.template>         <controltemplate>             <scrollviewer horizontalscrollbarvisibility="visible">                 <itemspresenter />             </scrollviewer>         </controltemplate>         </listbox.template> </listbox> 

this listbox inside pivot control. want add link or click event 1 following textblock.

<textblock foreground="red" text="{binding companyorindividual}" width="440"></textblock> 

so after clicking on companyorindividual textblock user should navigated other xaml page. how this. can please provide me code event handler ? can please provide me nay code or link through can resolve above issue ? if doing wrong please guide me.if there better idea above question please suggest it.

you can wrap textblock grid, , give transparent color. attach navigatetopageaction grid, this,

xmlns:custom="clr-namespace:system.windows.interactivity;assembly=system.windows.interactivity" xmlns:ic="clr-namespace:microsoft.expression.interactivity.core;assembly=microsoft.expression.interactions"  <grid background="transparent">     <custom:interaction.triggers>         <custom:eventtrigger eventname="mouseleftbuttondown">             <ic:navigatetopageaction targetpage="/views/yourview.xaml" />         </custom:eventtrigger>     </custom:interaction.triggers> <textblock foreground="red" text="{binding companyorindividual}" horizontalalignment="left"/> </grid> 

the reason need give grid color because doing able receive mouse click. please give try , let me know if have problems using it.

alternatively, can wrap textblock button, handle button's click event.

update:

matt right thing using mouseleftbuttondown/mouseleftbuttonup may bad.

in own project have created simple style button acts clickable textblock. thing of using button can receive tilteffect , allow commanding.

<style x:key="textbuttonstyle" targettype="button">     <setter property="background" value="transparent"/>     <setter property="borderbrush" value="{staticresource phoneforegroundbrush}"/>     <setter property="foreground" value="{staticresource phoneaccentbrush}"/>     <setter property="borderthickness" value="{staticresource phoneborderthickness}"/>     <setter property="fontfamily" value="{staticresource phonefontfamilysemilight}"/>     <setter property="fontsize" value="{staticresource phonefontsizelarge}"/>     <setter property="padding" value="{staticresource phonetouchtargetoverhang}"/>     <setter property="template">         <setter.value>             <controltemplate targettype="button">                 <grid background="transparent">                     <visualstatemanager.visualstategroups>                         <visualstategroup x:name="commonstates">                             <visualstate x:name="normal"/>                             <visualstate x:name="mouseover"/>                             <visualstate x:name="pressed"/>                             <visualstate x:name="disabled">                                 <storyboard>                                     <objectanimationusingkeyframes storyboard.targetproperty="foreground" storyboard.targetname="contentcontainer">                                         <discreteobjectkeyframe keytime="0" value="{staticresource phonedisabledbrush}"/>                                     </objectanimationusingkeyframes>                                 </storyboard>                             </visualstate>                         </visualstategroup>                     </visualstatemanager.visualstategroups>                     <contentcontrol x:name="contentcontainer" contenttemplate="{templatebinding contenttemplate}" content="{templatebinding content}" foreground="{templatebinding foreground}" horizontalcontentalignment="{templatebinding horizontalcontentalignment}" padding="{templatebinding padding}" verticalcontentalignment="{templatebinding verticalcontentalignment}"/>                 </grid>             </controltemplate>         </setter.value>     </setter>     <setter property="horizontalalignment" value="left"/>     <setter property="horizontalcontentalignment" value="stretch"/>     <setter property="verticalcontentalignment" value="stretch"/> </style> 

Comments