data binding - Enable TextBox when ListViewItem is selected in WPF (databinding) -


how can enable/disable textbox databinding in wpf when listviewitem (not) selected?

i have created converter class:

public class boolconvert : ivalueconverter {     public object convert(object value, type targettype, object parameter, cultureinfo culture)     {         return value == null;     }      public object convertback(object value, type targettype, object parameter, cultureinfo culture)     {         throw new exception("the method or operation not implemented.");     } } 

and added property textbox:

isenabled="{binding selecteditem, elementname=listviewcards, converter={staticresource boolconvert}}" 

but have xamlparseexception becouse canĀ“t find class :-(

you alternately use style trigger on textbox, eliminating need valueconverter:

<textbox>    <textbox.style>      <style targettype="{x:type textbox}">        <setter property="isenabled" value="false"/>        <style.triggers>          <datatrigger binding="{binding elementname=lvitems, path=selecteditem}" value="{x:null}">            <setter property="isenabled" value="true"/>          </datatrigger>        </style.triggers>      </style>    </textbox.style> </textbox> <listview name="lvitems" .../> 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -