c# - WPF Binding One TextBox to two Properties -


perhaps simple question, but... so, have bound text box property in viewmodel:

    <textbox x:name="ololo"  text="{binding vm.ololotext, mode=twoway, updatesourcetrigger=propertychanged}"> 

and there textblock near , change text property value due trigger logic have implemented beforehand:

<style targettype="textblock">      <style.triggers>           <datatrigger binding="{binding elementname=typegallery, path=selectedvalue}"               value="firsttype">         <setter property="text" value="aaa" />           </datatrigger>            <datatrigger binding="{binding elementname=typegallery, path=selectedvalue}"                 value="second type">             <setter property="text" value="bbb" />            </datatrigger>                                         ... 

so, textblock has values aaa or bbb . working charm. question how bind ololo textbox 1 property, vm.ololotext if there aaa value in textblock , other property (vm.ololotext2) if textblock value bbb ?

you use couple of datatriggers you:

<textbox x:name="ololo">     <textbox.style>         <style targettype="{x:type textbox}">             <setter property="text" value="{binding vm.ololotext}" />             <style.triggers>                 <datatrigger binding="{binding text, elementname=yourtextblock}"                     value="aaa">                     <setter property="text" value="{binding oneproperty}" />                 </datatrigger>                 <datatrigger binding="{binding text, elementname=yourtextblock}"                      value="bbb">                     <setter property="text" value="{binding anotherproperty}" />                 </datatrigger>             </style.triggers>         </style>     </textbox.style> </textbox> 

note binding vm.ololotext property work if textblock not have aaa or bbb in it.


Comments

Popular posts from this blog

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

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -