PLease i am having a severe problem in WPF listView Databinding. I bound the list view to a list varsList. and assign the item source of the listView to varsList.But when i change items in varsList they are changed in the list view but the display text of the items is not changed. I tried to use INotifyPropertyChanged but it does not work. The code is :
Variable Class:
public class Variable:INotifyPropertyChanged
{
private string name;
public string Name
{
get { return name; }
set { name = value; OnPropertyChanged("Name"); }
}
private VariableType type;
internal VariableType Type
{
get { return type; }
set { type = value; }
}
public Variable(string name,VariableType type)
{
this.name = name;
this.type= type;
}
public override string ToString()
{
return string.Format("{0} ({1})",name,type);
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
private void VariablesController_Loaded(object sender, RoutedEventArgs e)
{
Binding binding = new Binding();
binding.Source = VariablesTable.Variables;
//binding.Mode = BindingMode.TwoWay; (gives Error)
BindingOperations.SetBinding(lstVars, ListView.ItemsSourceProperty, binding);
if (lstVars.Items.Count != 0)
lstVars.SelectedIndex = 0;
}
private void btnEdit_Click(object sender, RoutedEventArgs e)
{
VariablesTable.Variables[0].Name = "Hani";
//I also tried the below code with out benifit
/* BindingExpression ex = lstVars.GetBindingExpression(ListBox.ItemsSourceProperty);
ex.UpdateSource();
ex.UpdateTarget();*/
}