C# 从childwindow添加数据后刷新silverlight datagrid
我想在从childwindow添加数据后刷新我的datagrid。 下面是我的家C# 从childwindow添加数据后刷新silverlight datagrid,c#,wpf,silverlight,datagrid,C#,Wpf,Silverlight,Datagrid,我想在从childwindow添加数据后刷新我的datagrid。 下面是我的家 public partial class Home : Page { ServiceReference1.Service1Client webService; public Home() { InitializeComponent(); webService = new ServiceReference1.Se
public partial class Home : Page
{
ServiceReference1.Service1Client webService;
public Home()
{
InitializeComponent();
webService = new ServiceReference1.Service1Client();
webService.ReadPismaCompleted += WebService_ReadPismaCompleted;
webService.ReadPismaAsync(0);
}
private void WebService_ReadPismaCompleted(object sender, ServiceReference1.ReadPismaCompletedEventArgs e)
{
if(e.Result != null)
{
dataGridPisma.ItemsSource = e.Result;
}
}
private void button_Click(object sender, System.Windows.RoutedEventArgs e)
{
ChildWindow1 childWindow = new ChildWindow1();
childWindow.Closed += ChildWindow_Closed;
childWindow.Show();
}
private void ChildWindow_Closed(object sender, System.EventArgs e)
{
if (( (ChildWindow1)sender).DialogResult.Value) webService.ReadPismaAsync(0);
}
添加数据后,我看不到任何更改(单击childwindow上的“确定”按钮“不刷新数据网格”)。我知道已经添加了数据,因为我在SQL server表中看到了数据,而且当我在web浏览器上刷新(按F5)时,我也看到了新数据。在
WebService\u ReadPismaCompleted
方法中使用PagedCollectionView
private PagedCollectionView _dataGridContext;
private void WebService_ReadPismaCompleted(object sender,serviceReference1.ReadPismaCompletedEventArgs e)
{
if(e.Result != null)
{
DataGridContext = new PagedCollectionView(e.Result)
}
}
public PagedCollectionView DataGridContext
{
get { return _dataGridContext; }
set {
_dataGridContext = value;
OnPropertyChanged("DataGridContext");
}
}
并设置您的DataGrid.DataContext=DataGridContext
添加此
`[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this,
new PropertyChangedEventArgs(propertyName));
}
}`
从setter中添加并删除
datagridPisma.DataContext=DataGridContext
。我在proprertychangednew上有一些错误,需要在类中实现INotifyPropertyChanged
接口。或者在不调用PropertyChanged的情况下尝试是否可以共享新的实现?在类中,我需要实现INOtifyPropertyChanged?在服务中,我有公共ObservableCollection ReadPisma(int barkod),我的类是Pismo,但我没有选择INotifyPropertyChanged的选项。您的类Home需要实现INotifyPropertyChanged
&设置this.DataContext=this代码>现在我的数据网格是空的,什么都没有。现在共享你的xaml。您应该有类似于ItemsSource={Binding DataGridContext}
的内容,正如您所说,我添加了ItemsSource,但没有帮助。我也有错误“找不到类型或命名空间名称NotifyPropertyChangedInvocator”删除[NotifyPropertyChangedInvocator]
attribute然后输入AutoGenerateColumns=True
仅用于测试。和This.DataContext=This