虚拟化WPF包装面板问题 [英] Virtualizing WPF Wrap Panel Issue

查看:122
本文介绍了虚拟化WPF包装面板问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WPF中使用的虚拟包装面板没有太多选择。出于某种原因或另一种MS决定不将其发布到标准库中。

There are not very many options for a virtualizing wrap panel for use in WPF. For one reason or another MS decided to not ship one in the standard library.

如果有人敢于向公众提供答案(和解释),以下codeplex项目的第一个工作项目,我将不胜感激:

If anyone could be so bold as to provide a crowd source answer (and explaination) to the first work item on the following codeplex project, I would greatly appreciate it:

http://virtualwrappanel.codeplex.com/workitem/1

谢谢!

问题摘要:

我最近尝试使用此项目中的虚拟包装面板,并且遇到了错误。

I've recently tried using the virtualizing wrappanel from this project and have encountered a bug.

复制步骤:


  1. 创建列表框。

  2. 将虚拟包装面板设置为列表框面板模板中的itemhost。

  3. 将列表框的itemsource绑定到可观察的集合中。


  1. Create listbox.
  2. Set the virtualizing wrappanel as the itemhost in a listboxpanel template.
  3. Bind the itemsource of the listbox to an observable collection.
  4. Remove an item from the backing observable collection.

Debug.Assert失败(Debug.Assert(child == _children [childIndex], MeasureOverride中的生成了错误的子级);),并且继续执行会导致Cleanup方法中出现空异常[请参见随附的屏幕截图]。

The Debug.Assert fails (Debug.Assert(child == _children[childIndex], "Wrong child was generated");) in MeasureOverride, and continued execution results in a null exception in the Cleanup method [see attached screenshot].

请让我知道您是否能够纠正此问题。

Please let me know if you are able to correct this.

谢谢,

AO

代码:

http://virtualwrappanel.codeplex.com/SourceControl/list/changesets#

替代文字http://virtualwrappanel.codeplex.com/Project/Download/AttachmentDownload.ashx?ProjectName=virtualwrappanel&WorkItemId=1&FileAttachmentId=138959

推荐答案

OnItemsChanged方法需要正确处理args参数。有关更多信息,请参见此问题。复制该问题的代码,您需要像这样更新OnItemsChanged:

The OnItemsChanged method needs to properly handle the args parameters. Please see this question for more information. Copying the code from that question, you would need to update OnItemsChanged like so:

protected override void OnItemsChanged(object sender, ItemsChangedEventArgs args) {
    base.OnItemsChanged(sender, args);
    _abstractPanel = null;
    ResetScrollInfo();

    // ...ADD THIS...
    switch (args.Action) {
        case NotifyCollectionChangedAction.Remove:
        case NotifyCollectionChangedAction.Replace:
            RemoveInternalChildRange(args.Position.Index, args.ItemUICount);
            break;
        case NotifyCollectionChangedAction.Move:
            RemoveInternalChildRange(args.OldPosition.Index, args.ItemUICount);
            break;
    }
}

这篇关于虚拟化WPF包装面板问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆