c# 4.0 - Textbox focus does not work when focus by mouseclick wpf -
when click on text box mouse focus not display. , when goes textbox keyboard focus displayed. trying below code. please can 1 suggest me how solve issue.
<style x:key="textboxfocusvisualstyle" > <setter property="control.template"> <setter.value> <controltemplate> <image source="/mit;component/resources/txtfocus.png" stretch="fill" margin="-8,-6,-8,-6"/> </controltemplate> </setter.value> </setter> </style> <textbox grid.column="2" height="44" margin="20,48,0,0" name="txtemailid" verticalalignment="top" keyboardnavigation.tabindex="2" maxwidth="400" horizontalalignment="left" width="350" text="" focusvisualstyle="{dynamicresource textboxfocusvisualstyle}" verticalcontentalignment="center" fontweight="semibold" fontsize="18" contextmenu="{x:null}" />
i tried below code after @hattenn answer:
<application x:class="wpfapplication1.app" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" startupuri="mainwindow.xaml"> <application.resources> <style x:key="textboxstyle" targettype="{x:type textbox}"> <style.triggers> <trigger property="isfocused" value="true"> <setter property="background"> <setter.value> <visualbrush> <visualbrush.visual> <grid> <image source="/wpfapplication1;component/resources/txtfocus.png" stretch="fill" margin="-8,-6,-8,-6"/> </grid> </visualbrush.visual> </visualbrush> </setter.value> </setter> </trigger> </style.triggers> </style> </application.resources>
and
<textbox height="23" name="textbox1" width="120" focusable="true" focusvisualstyle="{dynamicresource textboxstyle}"/>
but not work me. nothing happened. please suggest. thanks
focusvisualstyle
keyboard focus, can check out here:
http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.focusvisualstyle.aspx
for general focus, can use isfocused
property, more info below:
http://msdn.microsoft.com/en-us/library/system.windows.uielement.isfocused.aspx
as example, can try this:
<style x:key="textboxstyle" targettype="{x:type textbox}"> <style.triggers> <trigger property="isfocused" value="true"> <setter property="background"> <setter.value> <visualbrush> <visualbrush.visual> <grid> <image source="/mit;component/resources/txtfocus.png" stretch="fill" margin="-8,-6,-8,-6"/> </grid> </visualbrush.visual> </visualbrush> </setter.value> </setter> </trigger> </style.triggers> </style>
Comments
Post a Comment