代码之家  ›  专栏  ›  技术社区  ›  Jim

在WPF中,访问列表框中的容器

  •  0
  • Jim  · 技术社区  · 16 年前

    我在创造一个 DerivedListBox : ListBox 还有一个 DerivedHeaderedContentControl : HeaderedContentControl ,它将作为 ListBox .

    以计算扩展内容的可用大小 DerivedHeaderedContentControl s、 我将每个容器对象存储在 DerivedListBox . 这样我就可以计算出每一个标题的高度 派生HeaderedContentControl 派生列表框 派生HeaderedContentControl .

    public class DerivedHeaderedContentControl : HeaderedContentControl
    {
        // Do some binding to DerivedListBox to calculate height.
    }
    
    public class DerivedListBox : ListBox
    {
        private List<DerivedHeaderedContentControl> containers;
    
        protected override DependencyObject GetContainerForItemOverride()
        {
            DerivedHeaderedContentControl val = new DerivedHeaderedContentControl();
            this.containers.Add(val);
            return val;
        }
    
        // Do some binding to calculate height available for an expanded
        // container by iterating over containers.
    }
    

    派生列表框 ItemsSource 清除(或项目源中的项目被删除)。我如何确定 项目资源 被清除以便我可以清除容器列表?

    1 回复  |  直到 14 年前
        1
  •  0
  •   Pavel Minaev    16 年前

    对于这个特定的场景,您可能应该使用 ItemsContainerGenerator.ItemsChanged 事件。