c# - WPF Binding - Bind to A when X is checked, else bind to B -


basically have textblock displays microphone gain.

<textblock fontfamily="calibri light" fontsize="20" foreground="#fff65b60" fontweight="bold" height="35"><run text="{binding audiorecorder.gain, stringformat={}microphone gain: {0:#} %}"/></textblock> 

as can see, bound "audiorecorder.gain" want bind value if checkbox not checked.

<checkbox ischecked="{binding recognizer.autogaincontrol}" 

if checked, want bind to

"recognizer.gain"

is possible or have merge 2 gain variables together?

i not sure if did succeed or not example should remain here others might search same thing:

i have gathered info , created version of :

<window x:class="comboitems.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:windows="clr-namespace:system.windows;assembly=presentationcore"     xmlns:system="clr-namespace:system;assembly=mscorlib"     title="mainwindow" width="525"> <window.resources>     <x:array x:key="data1" type="{x:type system:string}">         <system:string>item1</system:string>         <system:string>item2</system:string>         <system:string>item3</system:string>     </x:array>     <objectdataprovider x:key="visibilityvalues"                              objecttype="{x:type system:enum}"                             methodname="getvalues">         <objectdataprovider.methodparameters>             <x:type typename="windows:visibility" />         </objectdataprovider.methodparameters>     </objectdataprovider> </window.resources>  <grid>       <stackpanel>         <radiobutton content="radiobutton1" name="radio1" groupname="radio"  />         <radiobutton content="radiobutton2" name="radio2"   groupname="radio"  />         <listbox name="listbox">             <listbox.style>                 <style targettype="listbox">                     <setter property="itemssource">                         <setter.value>                             <binding source="{staticresource data1}" />                         </setter.value>                     </setter>                     <style.triggers>                         <datatrigger binding="{binding path=ischecked, elementname=radio1}" value="true" >                             <setter property="itemssource">                                 <setter.value>                                     <binding source="{staticresource data1}" />                                 </setter.value>                             </setter>                         </datatrigger>                         <datatrigger binding="{binding path=ischecked, elementname=radio2}" value="true" >                             <setter property="itemssource">                                 <setter.value>                                     <binding source="{staticresource visibilityvalues}" />                                 </setter.value>                             </setter>                         </datatrigger>                     </style.triggers>                 </style>             </listbox.style>         </listbox>     </stackpanel>   </grid> </window> 

datatrigger job here , according ischecked property of both radiobuttons change source of listbox.

further more, have used binding enumerations of system.enum type’s getvalues method accepts type parameter knows enumeration’s values should return.

the above sample should work without modification.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -