C# Syncfusion SfDataGrid数据绑定问题&;DataGrid列中的唯一值

C# Syncfusion SfDataGrid数据绑定问题&;DataGrid列中的唯一值,c#,wpf,data-binding,syncfusion,datagridcomboboxcolumn,C#,Wpf,Data Binding,Syncfusion,Datagridcomboboxcolumn,我在数据绑定到SfDataGrid时遇到问题。我正在为我的简单项目使用MVVM体系结构。下面是我的简化项目(省略了一些代码): 型号: public class Combo : INotifyPropertyChanged { private string name; public ObservableCollection<LoadCase> LoadCases { get; set; } #region getters and setters p

我在数据绑定到SfDataGrid时遇到问题。我正在为我的简单项目使用MVVM体系结构。下面是我的简化项目(省略了一些代码):

型号:

public class Combo : INotifyPropertyChanged
{
    private string name;

    public ObservableCollection<LoadCase> LoadCases { get; set; }

    #region getters and setters
    public string Name
    {
        get
        {
            return name;
        }
        set
        {
            name = value;
        }
    }

    public Combo(....)
    {
        ....
    }
    .....

}
<Syncfusion:SfDataGrid x:Name="ComboInfoDG" Grid.ColumnSpan="3" AutoGenerateColumns="False" Margin="10,10,10,10" Grid.Row="3" Grid.Column="0"
                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding ObjCombo.LoadCases}" AllowEditing="True" EditTrigger="OnTap">
            <Syncfusion:SfDataGrid.Columns>
                <Syncfusion:GridComboBoxColumn  x:Name="Comboboxcolumn" HeaderText="Load Name"
                                        ItemsSource="{Binding DataContext.CombosAndLoadCasesList, ElementName=ComboInfoDG}"
                                        DisplayMemberPath="{Binding Name}"
                                        MappingName="Name"/>
                
                <Syncfusion:GridTextColumn HeaderText="Load factor" 
                                           MappingName="SF"/>
             </Syncfusion:SfDataGrid.Columns>
        </Syncfusion:SfDataGrid>
Combo.cs:

public class Combo : INotifyPropertyChanged
{
    private string name;

    public ObservableCollection<LoadCase> LoadCases { get; set; }

    #region getters and setters
    public string Name
    {
        get
        {
            return name;
        }
        set
        {
            name = value;
        }
    }

    public Combo(....)
    {
        ....
    }
    .....

}
<Syncfusion:SfDataGrid x:Name="ComboInfoDG" Grid.ColumnSpan="3" AutoGenerateColumns="False" Margin="10,10,10,10" Grid.Row="3" Grid.Column="0"
                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding ObjCombo.LoadCases}" AllowEditing="True" EditTrigger="OnTap">
            <Syncfusion:SfDataGrid.Columns>
                <Syncfusion:GridComboBoxColumn  x:Name="Comboboxcolumn" HeaderText="Load Name"
                                        ItemsSource="{Binding DataContext.CombosAndLoadCasesList, ElementName=ComboInfoDG}"
                                        DisplayMemberPath="{Binding Name}"
                                        MappingName="Name"/>
                
                <Syncfusion:GridTextColumn HeaderText="Load factor" 
                                           MappingName="SF"/>
             </Syncfusion:SfDataGrid.Columns>
        </Syncfusion:SfDataGrid>
ViewModel(我有两个视图共享同一视图模型):

public class Combo : INotifyPropertyChanged
{
    private string name;

    public ObservableCollection<LoadCase> LoadCases { get; set; }

    #region getters and setters
    public string Name
    {
        get
        {
            return name;
        }
        set
        {
            name = value;
        }
    }

    public Combo(....)
    {
        ....
    }
    .....

}
<Syncfusion:SfDataGrid x:Name="ComboInfoDG" Grid.ColumnSpan="3" AutoGenerateColumns="False" Margin="10,10,10,10" Grid.Row="3" Grid.Column="0"
                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding ObjCombo.LoadCases}" AllowEditing="True" EditTrigger="OnTap">
            <Syncfusion:SfDataGrid.Columns>
                <Syncfusion:GridComboBoxColumn  x:Name="Comboboxcolumn" HeaderText="Load Name"
                                        ItemsSource="{Binding DataContext.CombosAndLoadCasesList, ElementName=ComboInfoDG}"
                                        DisplayMemberPath="{Binding Name}"
                                        MappingName="Name"/>
                
                <Syncfusion:GridTextColumn HeaderText="Load factor" 
                                           MappingName="SF"/>
             </Syncfusion:SfDataGrid.Columns>
        </Syncfusion:SfDataGrid>
MainWindowViewModel.cs

 public class LoadCase : INotifyPropertyChanged
{
    private string name;
    private double sf;

    public string Name
    {
        get
        {
            return name;
        }
        set
        {
            name = value;
        }
    }

    public double SF
    {
        get
        {
            return sf;
        }
        set
        {
            sf = value;
        }
    }


    public LoadCase(....)
    {
          ....
    }
      ....
}
    public class MainWindowViewModel : INotifyPropertyChanged
{

    public Combo ObjCombo
    {
        get; set;
    }

    private ObservableCollection<object> combosandloadcasesList;
    public ObservableCollection<object> CombosAndLoadCasesList
    {
        get { return combosandloadcasesList; }
        set { combosandloadcasesList = value; }
    }

    public MainWindowViewModel()
    {
          ....
    }
       ...
}
我正在尝试添加一个将绑定到ObjCombo.LoadCases的SfDataGrid。那部分有效。然后我添加了两列;一个组合框和一个文本框。我的问题是组合框。组合框应绑定到ObjCombo.LoadCases Name属性,下拉列表应包含ComboAndLoadCaseSList中的对象。文本列工作正常,并绑定到ObjCombo.LoadCases SF属性。然而,我的组合框部分工作。它显示绑定到ComboandLoadCaseSList的对象,但下拉列表显示的是对象的类型,而不是对象的名称。我不确定DisplayMemeberPath为什么不工作

ChildView中的xaml:

public class Combo : INotifyPropertyChanged
{
    private string name;

    public ObservableCollection<LoadCase> LoadCases { get; set; }

    #region getters and setters
    public string Name
    {
        get
        {
            return name;
        }
        set
        {
            name = value;
        }
    }

    public Combo(....)
    {
        ....
    }
    .....

}
<Syncfusion:SfDataGrid x:Name="ComboInfoDG" Grid.ColumnSpan="3" AutoGenerateColumns="False" Margin="10,10,10,10" Grid.Row="3" Grid.Column="0"
                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding ObjCombo.LoadCases}" AllowEditing="True" EditTrigger="OnTap">
            <Syncfusion:SfDataGrid.Columns>
                <Syncfusion:GridComboBoxColumn  x:Name="Comboboxcolumn" HeaderText="Load Name"
                                        ItemsSource="{Binding DataContext.CombosAndLoadCasesList, ElementName=ComboInfoDG}"
                                        DisplayMemberPath="{Binding Name}"
                                        MappingName="Name"/>
                
                <Syncfusion:GridTextColumn HeaderText="Load factor" 
                                           MappingName="SF"/>
             </Syncfusion:SfDataGrid.Columns>
        </Syncfusion:SfDataGrid>

以下是调试器向我展示的内容:

  • 错误1 null无法将“”从类型“”转换为具有默认转换的“en-US”区域性的类型“System.Uri”;考虑使用转换器的绑定属性。NotSupportedException:'System.NotSupportedException:UriTypeConverter无法从(null)转换
  • 错误1在MainWindowViewModel类型的对象上找不到MainWindowViewModel名称GridComboBoxColumn.DisplayMemberPath字符串名称属性
  • 错误2在GridComboBoxColumn类型的对象上找不到GridComboxColumn名称GridComboxColumn.DisplayMemberPath字符串名称属性
  • 错误2 SfDataGrid,Name='ComboInfoDG'DataContext.CombosAndLoadCasesList GridComboBoxColumn.ItemsSource IEnumerable找不到目标元素的治理FrameworkElement或FrameworkContentElement
  • 错误1 MainWindowViewModel Name GridComboBoxColumn.DisplayMemberPath字符串找不到目标元素的治理FrameworkElement或FrameworkContentElement
  • 错误1 GridComboBoxColumn名称GridComboxColumn.DisplayMemberPath字符串找不到目标元素的治理FrameworkElement或FrameworkContentElement
当我在WPF中使用传统的DataGrid(代码稍有不同)时,我就可以做到这一点。我决定使用一个第三方框架,因为我认为它可能具有我将来可能需要的功能,而无需考虑如何实现它们。如果你已经做到了这一点,你能为我提供一些提示来实施以下内容(请提供任何指导):

  • 一种基于用户输入(在该组合框中)在每个组合框中实现过滤器的方法,该用户输入将过滤下拉列表
  • 在组合框列中仅允许唯一值
  • 仅允许该列中ComboAndLoadCaseSList中的值
  • 在我的窗口中有一个OK和cancel按钮,这样当用户按下cancel时,SfDataGrid中所做的任何更改都不会反映在绑定的变量中。如果用户按OK,则保存更改。有称为OldItemsSource和NewItemsSource的事件,但我不知道如何利用它们
  • 提前感谢您的帮助,如果有另一个框架/第三方DataGrid执行以下操作并且是免费的(社区许可证),请让我知道我很乐意切换

    SfDataGrid的文档: