我有一个绑定列表到DataGrid元素的问题。我创建了一个实现INotifyPropertyChange和保持订单列表类:绑定列表到DataGrid Silverlight
public class Order : INotifyPropertyChanged
{
private String customerName;
public String CustomerName
{
get { return customerName; }
set {
customerName = value;
NotifyPropertyChanged("CustomerName");
}
}
private List<String> orderList = new List<string>();
public List<String> OrderList
{
get { return orderList; }
set {
orderList = value;
NotifyPropertyChanged("OrderList");
}
}
public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
在XAML中有绑定的OrderList元素的简单DataGrid组件:
<data:DataGrid x:Name="OrderList" ItemsSource="{**Binding OrderList**, Mode=TwoWay}" Height="500" Width="250" Margin="0,0,0,0" VerticalAlignment="Center"
我也有在GUI中的按钮taht向OrderList添加元素:
order.OrderList.Add(“item”);
的DataContext设置为全局对象:
Order order = new Order();
OrderList.DataContext = order;
的问题是,当我点击该按钮,该项目不DataGrid中apear。它在点击网格行后显示。它接缝像INotifyPropertyChange不起作用... 我在做什么错?
请帮助:)
非常感谢。这很好:) – Rafal 2010-03-31 13:14:13