checkbox - Bind to a property and Element value - WPF binding -


i have checkbox binded object's property "isvalidcustomer" , have listview holds customers. whenever user selects customer in list, want checkbox checked property set false means "isvalidcustomer" property set false automatically. there way of achieving using wpf bindings?

any in regard highly appriciated.

regards

-srikanth

  • first make sure view's datacontext set viewmodel implements inotifypropertychanged interface add selectedcustomer property hold selected customer listview,

  • each time selectedcustomer set, check value , set isvalidcustomer property here full code :

the view model

 public class customer {     public string name { get; set; }     public string id { get; set; } } public partial class mainwindow : window, inotifypropertychanged {     private customer _selectedcustomer;     public customer selectedcustomer     {                 {             return _selectedcustomer;         }          set         {             if (_selectedcustomer == value)             {                 return;             }              _selectedcustomer = value;             onpropertychanged();             isvalidcustomer = (_selectedcustomer == null);          }     }     private observablecollection<customer> _listcustomers;     public observablecollection<customer> listcustomers     {                 {             return _listcustomers;         }          set         {             if (_listcustomers == value)             {                 return;             }              _listcustomers = value;             onpropertychanged();         }     }     private bool _isvalidcustomer = false;     public bool isvalidcustomer     {                 {             return _isvalidcustomer;         }          set         {             if (_isvalidcustomer == value)             {                 return;             }              _isvalidcustomer = value;             onpropertychanged();         }     }     public mainwindow()     {         initializecomponent();     }      public event propertychangedeventhandler propertychanged;      [notifypropertychangedinvocator]     protected virtual void onpropertychanged([callermembername] string propertyname = null)     {         propertychangedeventhandler handler = propertychanged;         if (handler != null) handler(this, new propertychangedeventargs(propertyname));     } } 

and view

  <stackpanel>     <checkbox content="isvalidcustomer" ischecked="{binding isvalidcustomer,mode=twoway}"></checkbox>     <listview itemssource="{binding listcustomers}" selecteditem="{binding selectedcustomer,mode=twoway}"></listview>         </stackpanel> 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -