不能在我的 DataGrid 中使用类型化的 DataRowView

本文关键字:类型化 DataRowView 我的 DataGrid 不能 | 更新日期: 2023-09-27 18:36:16

我们刚刚使用 Prism 启动了一个 WPF 项目。我们的问题是我们必须使用 System.Data.DataRowView 而不是 DataGrid 的类型化版本。我们像这样使用代码:

<DataGrid 
                    ItemsSource="{Binding Cars}" 
                    SelectedItem="{Binding ActiveCar}" 
                    AutoGenerateColumns="False" 
<!--[...]-->
<CheckBox Content="Four-wheel drive" IsChecked="{Binding TypedActiveCar.FourWheelDrive}"/>

<!--[...]-->
    private System.Data.DataRowView _activeCar;
    public System.Data.DataRowView ActiveCar
    {
        get { return _activeCar; }
        set
        {
            if (_activeCar!= value)
            {
                _activeCar= value;
                var fCarRow =
                    (_activeCar.Row as CarDS.F_CarRow);
                RaisePropertyChanged(() => ActiveCar);
                RaisePropertyChanged(() => TypedActiveCar);
            }
        }
    }
    public CarDS.F_CarRow TypedActiveCar
    {
        get
        {
            if (ActiveCar != null)
            {
                return ActiveCar.Row as CarDS.F_CarRow;
            }
            return null;
        }
    }
    public CarDS.F_CarDataTable Cars
    {
        get { return _data.F_Cars; }
        set
        {
            if (_data.F_Cars != value)
            {
                RaisePropertyChanged(() => Cars);
                RaisePropertyChanged(() => ActiveCar);
            }
        }
    }

此实现正在工作,但我更喜欢使用表中的类型化版本作为我的 SelectedItem。你有什么想法吗?

不能在我的 DataGrid 中使用类型化的 DataRowView

DataRows、DataViews、DataRowViews 和其他 System.Data Type 用于组织数据,在内部不依赖于任何 DataGrid 内容(可能概念上的除外)。此数据的显示旨在便于开发人员使用,并使用自己的体系结构,与 System.Windows.Controls 命名空间分开。您可以将信息从 DataRowView 转换为某种 DataGridRow,但这是您能做的最多的事情。