c# - XAML Change the image source inside a Togglebutton -
i'm trying alter image source (in xaml only) when togglebutton "ispressed" true. when iam trying bind property via ''image.trigger'' it's not working.
this have right , image showing want to.
<togglebutton x:name="pbstations" template="{staticresource contentonlytemplatetogglebutton}"> <stackpanel orientation="horizontal"> <image source="/sprites/misc/expanderbuttonclose.png" margin="2" stretch="uniform" x:name="img"> </image> <textblock text="stations" x:name="tbstations" style="{staticresource tbtriggergray}" /> </stackpanel> </togglebutton> this have tried doesn't work:
<togglebutton x:name="pbstations" template="{staticresource contentonlytemplatetogglebutton}"> <stackpanel orientation="horizontal"> <image source="/sprites/misc/expanderbuttonclose.png" margin="2" stretch="uniform" x:name="img"> <image.triggers> <datatrigger binding="{binding elementname=pbstations,path=ispressed}" value="true"> <setter targetname="img" property="image.source" value="/sprites/misc/expanderbuttonopen.png" /> </datatrigger> </image.triggers> </image> <textblock text="stations" x:name="tbstations" style="{staticresource tbtriggergray}" /> </stackpanel> </togglebutton>
try set triggers image within style image. here code
<togglebutton x:name="pbstations" template="{staticresource contentonlytemplatetogglebutton}"> <stackpanel orientation="horizontal"> <image margin="2" stretch="uniform" x:name="img"> <image.style> <style targettype="image"> <style.triggers> <datatrigger binding="{binding elementname=pbstations,path=ispressed}" value="true"> <setter property="source" value="/sprites/misc/expanderbuttonopen.png" /> </datatrigger> <datatrigger binding="{binding elementname=pbstations,path=ispressed}" value="false"> <setter property="source" value="/sprites/misc/expanderbuttonclose.png" /> </datatrigger> </style.triggers> </style> </image.style> </image> <textblock text="stations" x:name="tbstations" style="{staticresource tbtriggergray}" /> </stackpanel> </togglebutton> i moved image-setting logic in 2 info triggers. reason wpf engine evaluate image's source property after executing datatrigger datatrigger's setter have lower priority setting source property image hand.
note ispressed true when hold left mouse button downwards when release ispressed became false. there ischecked property togglebutton class can store state.
c# wpf visual-studio-2010 xaml
No comments:
Post a Comment