xaml - Silverlight Change Content Based on Control CheckState (Toggle multiple ContentPresenters) -


i change content of control based on current checkstate (checked, unchecked, indeterminate). if possible solution use xaml , require no code behind.

i wondering control use , how define multiple sets of content.

example: "togglecontent" control displays usercontrol1 when checked state unchecked , usercontrol2 when checked state checked.

the xaml might this:

        <togglecontent>             <togglecontent.contentunchecked>                 <local:usercontrol1></local:usercontrol1>             </togglecontent.contentunchecked>             <togglecontent.contentchecked>                 <local:usercontrol2></local:usercontrol2>             </togglecontent.contentchecked>         </togglecontent> 

i'm not sure "no code behind" means, sounds perfect example using valueconverter , changing visibility based on check state. this:

<stackpanel>     <checkbox x:name="mycheckbox"/>     <local:usercontrol1 visibility="{binding ischecked, elementname=mycheckbox, converter={staticresource booltovis}, converterparameter=false">     <local:usercontrol2 visibility="{binding ischecked, elementname=mycheckbox, converter={staticresource booltovis}, converterparameter=true"> 

the converter:

public class booleantovisibilityconverter : ivalueconverter {     public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         if (value == null) return visibility.collapsed;          bool comparer = true;         if(parameter != null)         {             comparer = system.convert.toboolean(parameter);         }         return system.convert.toboolean(value) == comparer ? visibility.visible : visibility.collapsed;     }      public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         throw new notimplementedexception();     } } 

here's nice post jeff wilcox on value converters


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -