wpf - Is there a MouseDown setter property for a rectangle that acts as a button control template? -


as title suggests, i'm looking trigger property triggers when left mouse button clicked on button. problem being button has rectangle it's control template , i'd change fill/stroke when button/rectangle clicked.

the trigger property can find works "ismouseover"

anything mousedown or ispressed doesn't work.

my xaml right now:

    <button x:name="my_button" click="my_button_click" margin="268,91,-266,-94">         <button.template>             <controltemplate>                 <rectangle horizontalalignment="left" height="20" stroke="black" verticalalignment="top" width="141" margin="105,10,0,0" strokethickness="2">                     <rectangle.style>                         <style targettype="{x:type rectangle}">                             <setter property="fill" value="blue" />                             <style.triggers>                                 <trigger property="ismouseover" value="true">                                     <setter property="fill" value="red"/>                                     <setter property="stroke" value="black"/>                                 </trigger>                             </style.triggers>                         </style>                     </rectangle.style>                 </rectangle>             </controltemplate>         </button.template>     </button> 

where trigger property "ismouseover" property mousedown, , proceeding set fill , stroke of rectangle different colors.

xaml i've tried hasn't worked:

                                <trigger property="mousedown" value="true">                                     <setter property="fill" value="red"/>                                     <setter property="stroke" value="black"/>                                 </trigger> 

edit: clarify ismouseover works trigger property, need when mouse clicked on button rather hovered over.

see datatrigger below :

    <button x:name="my_button" click="my_button_click" margin="268,91,-266,-94">         <button.template>             <controltemplate>                 <rectangle horizontalalignment="left" height="20" stroke="black" verticalalignment="top" width="141" margin="105,10,0,0" strokethickness="2">                     <rectangle.style>                         <style targettype="{x:type rectangle}">                             <setter property="fill" value="blue" />                             <style.triggers>                                 <datatrigger binding="{binding ispressed, relativesource={relativesource mode=templatedparent}}" value="true">                                     <setter property="fill" value="red"/>                                     <setter property="stroke" value="black"/>                                 </datatrigger>                             </style.triggers>                         </style>                     </rectangle.style>                 </rectangle>             </controltemplate>         </button.template>     </button> 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -