xaml - ControlTemplate Trigger -
<style targettype="{x:type textbox}"> <setter property="snapstodevicepixels" value="true" /> <setter property="overridesdefaultstyle" value="true" /> <setter property="keyboardnavigation.tabnavigation" value="none" /> <setter property="focusvisualstyle" value="{x:null}" /> <setter property="minwidth" value="120" /> <setter property="minheight" value="25" /> <setter property="allowdrop" value="true" /> <setter property="fontsize" value="16"/> <setter property="fontfamily" value="arial"/> <setter property="verticalcontentalignment" value="center"/> <setter property="verticalalignment" value="bottom"/> <setter property="template"> <setter.value> <controltemplate targettype="{x:type textboxbase}"> <border name="border" cornerradius="6" padding="2" borderbrush="black" borderthickness="2,1"> <scrollviewer margin="0" x:name="part_contenthost" /> </border> <controltemplate.triggers> </controltemplate.triggers> </controltemplate> </setter.value> </setter> </style>
the code above have text box. put in controltemplate.trigger in order border change color black blue or increase border size when clicked on. have tried few things without luck. includes style.triggers , events. please post code goes between controltemplate.trigger.
this assumes want border changed when have focused, since clicking textbox focuses it. there no onclick property available, changes border of textbox once have focused.
<trigger property="iskeyboardfocuswithin" value="true"> <setter property="borderbrush" targetname="border" value="blue"/> </trigger>
edit:
to remove focus, add following mousedown
event handler window or page:
mousedown="window_mousedown"
and in code behind:
private void window_mousedown(object sender, mousebuttoneventargs e) { keyboard.clearfocus(); }
this correctly remove focus textbox
, unset trigger have black bar again.
Comments
Post a Comment