c# - Change TextBox text and focus via CheckBox in XAML -


when check or uncheck checkbox, want clear textbox , set focus. implemented using code-behind.

my xmal:

<checkbox x:name="checkbox1" checked="checkbox1_checked" unchecked="checkbox1_checked" /> <textbox x:name="textbox1" text="hello" /> 

my c#:

private void checkbox1_checked(object sender, routedeventargs e) {     textbox1.text = "";     textbox1.focus(); } 

is possible in xaml?

use data triggers. work creating binding regular property, monitored changes.

for instance, consider following example:

<window x:class="wpftutorialsamples.styles.styledatatriggersample"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         title="styledatatriggersample" height="200" width="200">      <stackpanel horizontalalignment="center" verticalalignment="center">         <checkbox name="cbsample" content="hello, world?" />         <textblock horizontalalignment="center" margin="0,20,0,0" fontsize="48">              <textblock.style>                 <style targettype="textblock">                     <setter property="text" value="no" />                     <setter property="foreground" value="red" />                     <style.triggers>                         <datatrigger binding="{binding elementname=cbsample, path=ischecked}" value="true">                             <setter property="text" value="yes!" />                             <setter property="foreground" value="green" />                         </datatrigger>                     </style.triggers>                 </style>             </textblock.style>          </textblock>     </stackpanel> </window> 

in example, have checkbox , textblock. using datatrigger, bind textblock ischecked property of checkbox. supply default style, text "no" , foreground colour red, , then, using datatrigger, supply style when ischecked property of checkbox changed true, in case make green text saying "yes!" (as seen on screen shot).

you can find more in here.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

spring cloud - How to configure SpringCloud Eureka instance to point to https on non standard port -

javascript - Bootstrap Popover: iOS Safari strange behaviour -