简体   繁体   English

WPF DataGrid一些复选框在滚动时被重置

[英]WPF DataGrid Some checkboxes being reset on scroll

I've got a C# WPF application with a datagrid. 我有一个带有数据网格的C#WPF应用程序。 I have a custom class with a handful of public boolean properties, each with a get and set. 我有一个带有几个公共布尔属性的自定义类,每个属性都有一个get和set。

 public class OutlookPST
{
    public FileInfo PSTFileInfo { get; set; }   

    public Boolean Attached { get; set; }
    public Boolean FileLocal { get; set; }
    public Boolean LatestVersion { get; set; }
    public Boolean BackupExists { get; set; }
    public Boolean IgnoreDuplicate { get; set; }

    public Boolean CopyToLocalFlag { get; set; }
    public Boolean BackupToNetworkFlag { get; set; }  

In the xaml file, I have itemsource="Binding". 在xaml文件中,我具有itemsource =“ Binding”。

<DataGrid x:Name="dgPSTs" VirtualizingStackPanel.VirtualizationMode="Standard" VirtualizingStackPanel.IsVirtualizing="True" ItemsSource="{Binding}"  HorizontalAlignment="Left" Margin="10,121,0,0" VerticalAlignment="Top" Height="243" Width="1193"/>

I'm setting the datagrid ItemsSource property to a list of this custom class. 我将datagrid ItemsSource属性设置为该自定义类的列表。

private void OutlookPSTToDatagrid(List<OutlookPST> PSTs)
    {
        try
        {   
            dgPSTs.ItemsSource = PSTs;

When I do this, all the initial data looks good. 当我这样做时,所有初始数据看起来都不错。 All the boolean flags are checkboxes, which is what I want. 所有的布尔标志都是复选框,这就是我想要的。 All the data is correct. 所有数据均正确。 When I scroll down, just two of the boolean flags get set to checked. 当我向下滚动时,只有两个布尔标志设置为选中状态。 And when I scroll back up, the first rows are also checked, when they weren't before. 当我向上滚动时,也检查了前几行,而以前没有。

I don't understand how it's working for some of the flags and not the others. 我不明白它对某些标志(而不是其他标志)如何工作。

Anyone have any ideas? 有人有想法么? I can post some code if required. 如果需要,我可以发布一些代码。 Just let me know what parts of the code. 请让我知道代码的哪些部分。

Thanks! 谢谢!

Turns out the culprit was a pair of improperly formed lambda expressions elsewhere in the code: 事实证明,罪魁祸首是代码中其他地方的一对不正确的lambda表达式:

if (outlookPSTs.Where(x => x.CopyToLocalFlag = true).Count() > 0)

instead of: 代替:

if (outlookPSTs.Where(x => x.CopyToLocalFlag == true).Count() > 0)

Same sort of thing for the other boolean flag. 其他布尔标志也是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM