0

更新:看起来数据模板中的两行是减慢速度的原因。如果我只注释掉这两行,即

<Image Source="{Binding IconSelect}" Width="20" Height="20" />

<Image Source="{Binding IconBaseAcctFlag}" Width="20" Height="20" />

它工作正常。知道为什么在将列表呈现到列表视图时让这些图像在数据模板中冻结 GUI 吗?

我有一个包含两个面板的表单。左侧是树视图,当您单击一行时,它会检索该实体的相应数据并在右侧构建一个摘要窗格,由列表视图表示。

我在后台线程上获取和处理数据,然后在最终调用中使用 Application.Current.Dispatcher.Invoke() 将 ListView 的 ItemsSource 属性设置为我建立的集合。我原以为这会保持一个响应速度非常快的 GUI,但在更新 ItemsSource 属性时,GUI 会在这发生时冻结大约 1.5 秒,我不确定为什么要花这么长时间。

我还尝试在开始时绑定一个空的 ObservableCollection,然后在每次添加到集合时调用调度程序。这使它的响应速度更快,但是面板逐行加载,但仍然不是我想要的性能,而且代码最终会因为调度程序调用而变得非常混乱。

谁能建议这里可能是什么问题?当然,您可以将包含大约 12-20 个条目的通用集合绑定到列表视图并让它几乎立即更新?

public void DisplayAcctSummary(RbcUIAccount selAcct)
{
    if (selAcct == null)
    {
        ClearBaseAcctTransSummary();
        return;
    }

    InvokeUpdate(() => gbBaseDetails.Header = "Account Details");
    InvokeUpdate(() => lvBaseAccountDetails.ItemsSource = null);

    SelBoolValueForSelectedQueue();

    var lstBaseAcctDetails = new ObservableCollection<RbcUIBaseAcctDetails>();

    if (selCustSummary != null)
    {
        var offsetAllowed = IsOffselAllowed(selAcct.Branch);
        lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Account No:", selAcct.AccountId));
        lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Account Name:", selAcct.AcctDesc));
        lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Account Type:", ((RbcEnums.AccountType)selAcct.AccountType).ToString()));

        if (selAcct.Branch != string.Empty)
        {
            var rbcBranch = RbcStaticData.GetBranchbyID(selAcct.Branch.Trim());
            lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Branch:", rbcBranch.BranchName));
        }

        if (!IsInCURView && !IsInCURPendingView)
        {
            var serviceLayer = new RbcServiceLayer();
            var account = serviceLayer.GetAccountById(selAcct.AccountId, UserSession.SecurityContext);

            if (account != null)
            {
                if (account.BaseId != string.Empty)
                {
                    lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Current Balance:", selAcct.CurrentBalance, false, selAcct.DisplayUSDRate));

                    if (!offsetAllowed || (IsInCCMPView) || (IsInCCMPPendingView))
                    {
                        lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Available Balance:", selAcct.AvailableBalance, false, selAcct.DisplayUSDRate));
                        lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Available Funds:", selAcct.AvailableFunds, false, selAcct.DisplayUSDRate));
                        lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Base Sublimit:", rbcUtils.DisplayAmount(selAcct.BaseSublimit)));
                        lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Available Funds SL:", selAcct.AvailableFundsSL, false, selAcct.DisplayUSDRate));
                    }

                    if (!IsInCustomerEnquiryView && !offsetAllowed)
                    {
                        var excessToday = new RbcMoney();
                        var totAwtToday = SumTotalAwtForAccount(selAcct.AccountId);
                        var totAwtAllDates = SumTotalAwtAllDatesForAccount(selAcct.AccountId);

                        excessToday.Amount = totAwtToday.Amount - selAcct.AvailableFunds.Amount;
                        excessToday.Currency = totAwtToday.Currency;

                        if (excessToday.Amount < 0)
                            excessToday.Amount = 0;

                        lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Total Awaiting Today:", new RbcMoney(Math.Round(totAwtToday.Amount), totAwtToday.Currency), false, selAcct.DisplayUSDRate));
                        lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Total Excess Today:", new RbcMoney(Math.Round(excessToday.Amount), excessToday.Currency), false, selAcct.DisplayUSDRate));
                        lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Total Awaiting All Dates:", new RbcMoney(Math.Round(totAwtAllDates.Amount), totAwtAllDates.Currency), false, selAcct.DisplayUSDRate));

                        if (customer.Category != Convert.ToByte((CustCategory.Today)))
                        {
                            lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Total Awaiting Future:", selAcct.TotalAwaitingToday, false, selAcct.DisplayUSDRate));
                            lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Total Excess Future:", selAcct.TotalExcessToday, false, selAcct.DisplayUSDRate));
                        }
                    }
                }
                else
                {
                    lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Current Balance", selAcct.CurrentBalance, false, selAcct.DisplayUSDRate));

                    if (!offsetAllowed && account.BaseId != string.Empty)
                    {
                        lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Available Balance:", selAcct.AvailableBalance, false, selAcct.DisplayUSDRate));
                        lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Available Funds:", selAcct.AvailableFunds, false, selAcct.DisplayUSDRate));
                        lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Available Funds SL:", selAcct.AvailableFundsSL, false, selAcct.DisplayUSDRate));
                    }
                }
            }

            if (IsInCCMPView || IsInCCMPPendingView)
            {
                lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails(AppString.CustomerSummary.EarmarkPaymentDate, "0", true, string.Empty));
            }
        }

        if (!IsInCURView && !IsInCustomerEnquiryView)
        {
            var txnCount = 0;
            double totAmount = 0;
            RbcUITransaction transaction;

            foreach (var t in selAcct.Transactions)
            {
                transaction = t;
                var amount = rbcUtils.GetAmountInCustomerCurency(transaction.Amount.Amount, transaction.Amount.Currency, customer.CustCurrencyId);
                totAmount += amount;
                txnCount++;
            }

            lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("No of Txns:", txnCount.ToString()));
            lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Value of Txns:", new RbcMoney(totAmount, customer.CustCurrencyId), false, true));
            lstBaseAcctDetails.Add(new RbcUIBaseAcctDetails("Last updated at:", selAcct.LastUpdatedAt.ToString("dd-MM-yyyy HH:mm") + " GMT"));
        }
    }

    InvokeUpdate(() => lvBaseAccountDetails.ItemsSource = lstBaseAcctDetails);
}

更新:这是 ListView 的 XAML

<ListView x:Name="lvBaseAccountDetails" Margin="10,10,10,10" Background="#F4F8FB" ItemsSource="{Binding}" MouseDoubleClick="lvBaseAccountDetails_MouseDoubleClick" ItemContainerStyle="{StaticResource myHeaderStyleColor}">
                <ListView.View>
                    <GridView ColumnHeaderContainerStyle="{StaticResource myHeaderStyle}">
                        <GridView.Columns>
                            <GridViewColumn Header=""  >
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate >
                                        <Grid>
                                            <Image Source="{Binding IconSelect}" Width="20" Height="20" />
                                        </Grid>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="200" Header="" DisplayMemberBinding="{Binding SubBaseAcctType}" >
                            </GridViewColumn>
                            <GridViewColumn Width="200" Header=""  DisplayMemberBinding="{Binding SubBaseAcctValue}">
                            </GridViewColumn>
                            <GridViewColumn Header=""  >
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate >
                                        <Grid>
                                            <Image Source="{Binding IconBaseAcctFlag}" Width="20" Height="20" />
                                        </Grid>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView.Columns>
                    </GridView>
                </ListView.View>
            </ListView>
4

0 回答 0