This is how my program behaves as you enter numbers:

I have a list attached to an observable collection. Here is my code: (you can skip this part, the classes are very simple)
Grade:
public class Item : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
void UpdateSum()
{
Sum = Col1;
}
decimal _Col1;
public decimal Col1
{
get
{
return _Col1;
}
set
{
if (value > 100)
{
Col1 = 100;
NotifyPropertyChanged("Col1");
}else
{
_Col1 = value;
}
UpdateSum();
NotifyPropertyChanged("Col1");
}
}
decimal _Sum;
public decimal Sum
{
get
{
return _Sum;
}
set
{
_Sum = value;
NotifyPropertyChanged("Sum");
}
}
}
Code for
using System;
using System.Windows;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace WpfApplication3
{
public partial class MainWindow : Window
{
public ObservableCollection<Item> Collection = new ObservableCollection<Item>();
public MainWindow()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Collection.Add(new Item());
listView2.DataContext = Collection;
listView2.ItemsSource = Collection;
listView2.IsSynchronizedWithCurrentItem = true;
}
}
}
List in xaml:
<ListView Name="listView2" >
<ListView.View>
<GridView>
<GridViewColumn Header="Column1" Width="200">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="200" Text="{Binding Col1, UpdateSourceTrigger=PropertyChanged}"></TextBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Sum" Width="200">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="200" Text="{Binding Sum, UpdateSourceTrigger=PropertyChanged}"></TextBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
In any case, when I update Col1=100, it is not updated in the list! Also note how the amount is 100, not 1000.
I do not want column1 to be greater than some number x. In my real program, this number changes dynamically, and I compute it inside the Item class.
How can i fix this?
Edit
I found something interesting ... If I start typing in different taks numbers, see what happens: I just type 5 in this example:

It works in step 3 !!!
100, ...