c# - WPF MVVM dependency Property Get negative value -


i have 2 buttons, send , unsend. want enable or disable buttons using boolean issended.

i've created dependency property can used enable 1 of buttons, how can take negative value control other button?

view

dxb:barbuttonitem content="send" isenabled="{binding !issent}"  dxb:barbuttonitem content="unsend" isenabled="{binding issent}"  

viewmodel

public boolean issent {    { return (boolean) getvalue(issendedproperty); }    set { setvalue(issendedproperty, value); } }  public static readonly dependencyproperty issendedproperty = dependencyproperty.register("issent", typeof(boolean), typeof(viewmodel), new propertymetadata(default(boolean))); 

there number of in wpf; ivalueconverters, datatemplate or overriding controltemplate.

it hard know best in long run particular application, simplest show here ivalueconverter.

add class called, example, negateboolconverter

public class negateboolconverter : ivalueconverter {     public object convert(object value, type targettype, object parameter, cultureinfo culture)     {         return !(bool)value;     }       public object convertback(object value, type targettype, object parameter, cultureinfo culture)     {         return !(bool)value;     } } 

create instance of class in xaml (i put converters way in app.xaml, put in <window.resources> section.

  <window.resources>     <local:negateboolconverter x:key="myconverter"/>   </window.resources> 

where local: namespace converter class

then binding becomes:

  <dxb:barbuttonitem content="send" isenabled="{binding issended, converter={staticresource myconverter}}"> 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -