【发布时间】:2011-06-15 21:14:59
【问题描述】:
H 我使用 SQL CE 和 LINQ。我在 WPF Toolkit 的 Datagrid 控件的 ItemSource 上绑定属性 typeof Table。
类似的东西。
public Table<TestNick> MySource
{
get { return _tab; }
set
{
_tab = value;
NotifyPropertyChanged("MySource");
}
}
<Controls:DataGrid Name="Dg"
ItemsSource="{Binding Path=MySource, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
Grid.Row="0"/>
我使用 LINQ 从数据库中检索数据:
const string connStr = @"Spiri_SQL_CE_DB.sdf";
_dc = new Spiri_SQL_CE_DB(connStr);
MySource = _dc.TestNick;
如果我在最后一行添加断点,我会看到表 TestNick 中的所有值,但它不会在 DataGrid 中加载这些数据。
什么不好?
编辑:
我在后面的代码中检查了DataGrid控件的ItemSource,项目源是正确的,但我在DataGrid(视图)中看到“旧数据”。
所以绑定一定要正确,问题是DataGrid控件没有刷新数据。
【问题讨论】:
-
只是猜测,输出窗口中是否存在BindingExpression错误?
-
绑定没问题,DataGrid 的ItemSource 属性包含了很好的数据,但是在视图中我看到的是旧数据。
-
您可以删除 UpdateSourceTrigger=PropertyChanged,因为它不需要
标签: wpf linq linq-to-sql datagrid toolkit