我正在尝试在数据网格中显示数据,但未显示任何数据。通过断点时,我了解了以下内容:
我不确定为什么它没有填充,因为它在DataContext中有数据
<DataGrid Name="grdSalesCart" Grid.Column="1" Grid.ColumnSpan="12" Grid.Row="12" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
AutoGenerateColumns="False" CanUserSortColumns="false" ScrollViewer.VerticalScrollBarVisibility="Auto" CanUserAddRows="False">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Remove Item" Width="3*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Name="btnRemoveItem" Content="Remove Item" Click="btnRemoveItem_Click"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Edit Item" Width="2*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Name="btnEditItem" Content="Edit Item" Click="btnEditItem_Click"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="SKU" Width="2*" Binding="{Binding intItemIndicator, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" IsReadOnly="True"/>
<DataGridTextColumn x:Name="txtCartQuantity" Header="Quantity" Width="3*" Binding="{Binding intQuantity, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" IsReadOnly="True"/>
<DataGridTextColumn Header="Description" Width="9*" Binding="{Binding varItemDescription, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" IsReadOnly="True"/>
<DataGridTextColumn Header="Price" Width="3*" Binding="{Binding intItemPrice, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, Converter={StaticResource Double}}" IsReadOnly="True"/>
<DataGridTemplateColumn Header="Discount" Width="3*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TextBox Name="txtDiscountAmountCart" Text="{Binding intItemDiscount, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" IsEnabled="False"/>
<CheckBox Name="chkDiscountPercent" Content="Percent?" IsChecked="{Binding bitIsPercentageDiscount, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" IsEnabled="False"/>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
private Receipt receipt;
private ObservableCollection<ReceiptItem> ocReceiptItem;
private void UpdateCartAndTotals()
{
TransactionManager TM = new TransactionManager();
receipt = TM.ReturnReceiptTotalsAndCart(receipt);
ocReceiptItem = receipt.lstReceiptItem;
grdSalesCart.DataContext = ocReceiptItem;
//DataContext = ocReceiptItem;
//grdSalesCart.ItemsSource = DGM.ReturnSelectedDataTable(13, criteria).DefaultView;
}
我看过的其他一些stackoverflow问题: