wpf - getting valuechanged of a textbox which is binded to a datagrid celected cell -
i new wpf , mvvm.
let me explain u wht doin
i have entity class in datamodel seperate project
public class employee: inotifypropertychanged { private string _no; public string no { { homecoming _no; } set { _no= value; if (propertychanged != null) propertychanged(this, new propertychangedeventargs("no")); } } private string _name; public string name { { homecoming _name; } set { _name = value; if (propertychanged != null) propertychanged(this, new propertychangedeventargs("name")); } } }
now getting list , passing viewmodel
in viewmodel giving itemsource datagrid
in views have
<datagrid selectionmode="single" itemssource="{binding employeelist}" isreadonly="true" selecteditem="{binding selectedemployee}">
outside of grid
<textbox text="{binding selectedemployee.name}"/>
now when changing name in text box need have valuechange in viewmodel
public employee selectedemployee { { homecoming _selectedemployee; } set { if (_selectedemployee== value) { return; } _selectedemployee= value; createchart(getcurve.getpqvalues());**//i need phone call method whenever name changed** raisepropertychanged("selectedemployee"); } }
any suggestions highly helpful.
if procedure has corrected please guide me :-)
<grid> <grid.rowdefinitions> <rowdefinition height="*"/> <rowdefinition height="*"/> </grid.rowdefinitions> <combobox itemssource="{binding students}" selectedvalue="{binding text, elementname=mytextbox}" selectedvaluepath="name" selecteditem="{binding selectedstudent}" displaymemberpath="name"/> <textbox grid.row="2" x:name="mytextbox" /> </grid> public partial class mainwindow : window { public mainwindow() { initializecomponent(); students = new observablecollection<student>(); students.add(new student() { name = "harish", rollno = 1, isselected = false }); students.add(new student() { name = "arev", rollno = 2, isselected = false }); students.add(new student() { name = "pankaj", rollno = 3, isselected = true }); students.add(new student() { name = "deepak", rollno = 4, isselected = false }); datacontext = this; } public observablecollection<student> students { get; set; } //notify property havent did here because had done correctly public pupil selectedstudent {get;set;} } public class pupil { public string name { get; set; } public int rollno { get; set; } public bool isselected { get; set; } }
i hope help. bind text property of textbox selectedvalue property of combobox , give name selectedvaluepath
wpf mvvm entity
No comments:
Post a Comment