我遇到了一个问题,无法将 DataTable
绑定到 DataGrid
。我已经搜索了各种解决方案,但仍无法消除错误。使用 WindowsForms 时,绑定正常,因此 DataTable
是正确的。 我只是无法将其绑定到 WPF-DataGrid。
错误信息: AmbiguousMatchException was unhandled
Source: mscorlib
我已经建立了一个新项目,以排除任何坏链接等问题。
XAML 代码:
<DataGrid x:Name="grid1" Margin="10" ItemsSource="{Binding}"
AutoGenerateColumns="True"></DataGrid>
我已经尝试过以下 C# 代码:
grid1.ItemsSource = dt.DefaultView;
或者grid1.DataContext = dt.DefaultView;
或者grid1.DataContext = dtex;
感激任何帮助。
DataTable
结构。同时,如果你是从代码后台进行设置,那么就不需要在 xaml 中设置ItemsSource
。 - Rohit Vats