简体   繁体   English

删除行后数据网格不更新

[英]Datagrid Not Updating after removing row

Hi there i am using wpf mvvm and my datagrid not updating scource after removing row can any one help please here is my viewmodel:嗨,我正在使用 wpf mvvm 并且我的数据网格在删除行后没有更新源可以任何人帮忙请这是我的视图模型:

public class UserPaymentsVM : ViewModelBase
    {
        private IDataProvider _dataProvider;
        private int _selectedClientID;
        public Clients Client { get; set; }
        private List<Payments> _payments;
        public List<Payments> payments
        {
            get { return _payments; }
            set { _payments = value; RaisePropertyChanged(nameof(payments)); }
        }

and here is my view这是我的观点

    <Grid Background="Azure">
        <DataGrid ItemsSource="{Binding Path=payments, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

                  AutoGenerateColumns="True" 
                  Height="350" 
                  VerticalAlignment="Top"
                  SelectedValuePath="pid"
                 SelectedValue="{Binding PayID}">
        </DataGrid>
        <Button  Height="50" Width="100" Content="Remove" HorizontalAlignment="Center" VerticalAlignment="Bottom" Command="{Binding RemovePayment}"/>
    </Grid>
</UserControl>

您应该将数据网格绑定到 Observable 集合并实现 INotifyCollectionChanged 接口,以便在动态更改时通知侦听器,例如何时删除项目或刷新整个列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM