c# - 使用 itemssource - datagrid wpf 之前,项目集合必须为空

标签 c# wpf datagrid

当我尝试显式定义数据网格列时,我不断收到此错误。如果我注释掉 3 个 datagridtext 列,它就可以工作(但我显然想隐藏一些列)。在我的代码中,我所做的就是设置 DataGridLookupsTab 的数据上下文..不要弄乱 itemsource 或我的代码中的任何内容。知道我在这里可能做错了什么吗?

谢谢!

<TabItem Header="Lookups" Height="23" VerticalAlignment="Top">
            <Grid x:Name="DataGridLookupsTab" Background="#FFE5E5E5" Margin="0,0,-1,-2" DataContext="Apps.OMS.Models.Lookups">
                <ComboBox x:Name="ComboBoxDistinctLookups" HorizontalAlignment="Left" Margin="128,14,0,0" VerticalAlignment="Top" Width="228" ItemsSource="{Binding Path=LookupTypeList}" SelectionChanged="ComboBoxDistinctLookups_SelectionChanged"/>
                <Label Content="Select Lookup Type" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" RenderTransformOrigin="1.105,4.731"/>
                <DataGrid x:Name="DataGridLookups" HorizontalAlignment="Left" Margin="10,41,0,0" VerticalAlignment="Top" Width="768" Height="327" ItemsSource="{Binding LookupRecords}" > 
                    <DataGridTextColumn Binding="{Binding LookupType}" Header="Lookup Type" />
                    <DataGridTextColumn Binding="{Binding LookupValue}" Header="Lookup Value" />
                    <DataGridTextColumn Binding="{Binding LookupDescription}" Header="Lookup Description" />
                </DataGrid>
            </Grid>
        </TabItem>

最佳答案

实际上,问题最终是我缺少 Datagrid.Columns 标签。 谢谢

关于c# - 使用 itemssource - datagrid wpf 之前,项目集合必须为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11814058/

相关文章:

C# WPF 数据网格 : Column count always equal to 0

c# - C#中的换行符

c# - 小Q谈js和sharepoint

c# - 如何在 Visual Studio 中为 Windows 计算机上的 Xamarin 应用程序设计用户界面?

c# WPF AlternateContent 在命名空间中不存在 [...]

Delphi Grid DrawColumnCell无法清除

c# - C#使用来自两个不同线程的单例

WPF Animate 双属性更改

wpf - 为什么只有 Silverlight for WP7 有合成线程?

c# - 如何在后面的代码中更改 DataGrid 列的标题?