Wpf 从视图模型中选择datagrid行中的所有复选框

Wpf 从视图模型中选择datagrid行中的所有复选框,wpf,select,mvvm,datagrid,checkbox,Wpf,Select,Mvvm,Datagrid,Checkbox,我在WPF应用程序中使用Caliburn Micro作为MVVM框架。我对如何在datagrid控件中选中所有复选框没有什么问题。每个datagrid行都有复选框 我绑定列表的datagrid属性类型 型号: public class Bill : INotifyPropertyChanged { public string CellPhoneNo { get { return _cellPhoneNo; } set {

我在WPF应用程序中使用Caliburn Micro作为MVVM框架。我对如何在datagrid控件中选中所有复选框没有什么问题。每个datagrid行都有复选框

我绑定列表的datagrid属性类型

型号:

public class Bill : INotifyPropertyChanged
{

    public string CellPhoneNo
    {
        get { return _cellPhoneNo; }
        set
        {
            _cellPhoneNo = value;
            NotifyPropertyChanged("CellPhoneNo");
        }
    }

    public bool IsSelected
    {
        get { return _isSelected; }
        set
        {
            _isSelected = value;
            NotifyPropertyChanged("IsSelected");
        }
    }
视图模型:

    public IList<Bill> TmobileBill
    {
        get
        {
            return _tmobileBill;
        }
        set
        {
            _tmobileBill = value;
            NotifyOfPropertyChange(()=>TmobileBill);
        }
    }
视图中的复选框未选中。问题的根源是什么

多谢各位

  • 尝试将
    IList
    更改为
    ObservableCollection
  • 尝试使用简单绑定
  • 出于调试目的,请定义下一个控件的复选框,以查看实际绑定到RowItem的内容:

    <TextBlock Text="{Binding}"></TextBlock>
    

    您使用的是哪种类型的控件?(数据网格)
    <Controls:DataGrid.RowHeaderTemplate>
        <DataTemplate>
            <Grid>
                <CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay,
                          RelativeSource={RelativeSource FindAncestor,
                          AncestorType={x:Type Controls:DataGridRow}}}"/>
            </Grid>
        </DataTemplate>
    </Controls:DataGrid.RowHeaderTemplate>
    
                foreach (var row in TmobileBill)
                {
                    row.IsSelected = true;
                }
    
    <TextBlock Text="{Binding}"></TextBlock>