1. <tfoot id='Vp9XV'></tfoot>
    <i id='Vp9XV'><tr id='Vp9XV'><dt id='Vp9XV'><q id='Vp9XV'><span id='Vp9XV'><b id='Vp9XV'><form id='Vp9XV'><ins id='Vp9XV'></ins><ul id='Vp9XV'></ul><sub id='Vp9XV'></sub></form><legend id='Vp9XV'></legend><bdo id='Vp9XV'><pre id='Vp9XV'><center id='Vp9XV'></center></pre></bdo></b><th id='Vp9XV'></th></span></q></dt></tr></i><div id='Vp9XV'><tfoot id='Vp9XV'></tfoot><dl id='Vp9XV'><fieldset id='Vp9XV'></fieldset></dl></div>

    <small id='Vp9XV'></small><noframes id='Vp9XV'>

    1. <legend id='Vp9XV'><style id='Vp9XV'><dir id='Vp9XV'><q id='Vp9XV'></q></dir></style></legend>
      • <bdo id='Vp9XV'></bdo><ul id='Vp9XV'></ul>

    2. 如何在“绑定时间"获取 ListBox 中项目的 ListBoxItem

      How to get the ListBoxItem for an item in ListBox on quot;bind-timequot;(如何在“绑定时间获取 ListBox 中项目的 ListBoxItem)
    3. <legend id='kCOXN'><style id='kCOXN'><dir id='kCOXN'><q id='kCOXN'></q></dir></style></legend>
    4. <i id='kCOXN'><tr id='kCOXN'><dt id='kCOXN'><q id='kCOXN'><span id='kCOXN'><b id='kCOXN'><form id='kCOXN'><ins id='kCOXN'></ins><ul id='kCOXN'></ul><sub id='kCOXN'></sub></form><legend id='kCOXN'></legend><bdo id='kCOXN'><pre id='kCOXN'><center id='kCOXN'></center></pre></bdo></b><th id='kCOXN'></th></span></q></dt></tr></i><div id='kCOXN'><tfoot id='kCOXN'></tfoot><dl id='kCOXN'><fieldset id='kCOXN'></fieldset></dl></div>

        <tbody id='kCOXN'></tbody>
      • <small id='kCOXN'></small><noframes id='kCOXN'>

        <tfoot id='kCOXN'></tfoot>

          • <bdo id='kCOXN'></bdo><ul id='kCOXN'></ul>

                本文介绍了如何在“绑定时间"获取 ListBox 中项目的 ListBoxItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个带有 Foo 对象的 ListBox,并且基于某些事件,我禁用/启用了 ListBox 中的 ListBoxItems.使用 ListBox.Items 属性,我找到了 Foo 对象,据我所知,我需要使用以下函数来获取 Foo 的 ListBoxItem 容器.正确的?

                I have a ListBox with Foo objects, and based on some events I disable/enable the ListBoxItems in the ListBox. Using the ListBox.Items property I find Foo objects, and from what I've understood I need to use the following function to get the ListBoxItem container for the Foo. Correct?

                foreach (var item in Items)
                {
                    var lbi = ItemContainerGenerator.ContainerFromItem(foo) as ListBoxItem;
                    // do something
                }
                

                实际上我有一个自定义控件 FilteringListBox 继承 ListBox 并为其添加了一个额外的属性.上面的代码在自定义控件后面的代码中,并且在创建 FilteringListBox 时工作得很好.然而,我的问题是,当某些属性被绑定时,我会尝试这样做.我有一个属性 FilteringCollection 和一个在绑定时触发的 PropertyCallback.在此回调中,我将存储 FilteringCollection,但我还将执行初始过滤 - 运行集合并禁用任何表示 FilteringCollection 中的 Foo 的 ListBoxItem.

                Actually I have a custom control FilteringListBox which inherit ListBox and adds an extra property to it. The above code is in the code behind of the custom control and works just fine when the FilteringListBox is done being created. My problem however is that I try doing this when some property is bound. I have a property FilteringCollection and a PropertyCallback triggered when this is bound. In this callback I will store the FilteringCollection, but I will also do the initial filtering - running through the set collection and disable any ListBoxItem representing a Foo which is in the FilteringCollection.

                这就是我遇到问题的地方.我找到了所有的 Foo,所以我验证了 ItemsSource 是否已设置,但是执行 ItemContainerGenerator.ContainerFromItem 我得到了 null.就像尚未创建 ListBoxItems 一样.不是吗?这是我的绑定:

                This is where I get problems. I find all the Foos, so I verify that the ItemsSource is set, but doing the ItemContainerGenerator.ContainerFromItem I get null. It's like the ListBoxItems aren't created yet. Aren't they? Here is my binding:

                <custom:FilteringListBox ItemsSource="{Binding AvailableFoos}" FilteringCollection="{Binding AlreadyIncludedFoos}"></custom:FilteringListBox>
                

                所以;要么:如何在绑定时间"上获取 ListBoxItems?或者——如果我不能;是否有一些我可以覆盖的事件告诉我 ListBox 已完成创建 ListBoxItems?在没有运气的情况下尝试了 OnInitialized...

                So; either: How can I get the ListBoxItems on "bind-time"? Or - if I can't; is there some event I can override that tells me the ListBox is done creating ListBoxItems? Tried OnInitialized without luck...

                推荐答案

                其实更好的解决方案似乎是使用 ItemContainerGenerator.在创建时连接事件处理程序:

                Actually a better solution seems to be using the ItemContainerGenerator. Hook up an event handler on creation:

                ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged;
                

                并让事件处理程序做需要做的事情:

                And make the event handler do what needs to be done:

                protected void ItemContainerGenerator_StatusChanged(object sender, System.EventArgs e)
                {
                    if (ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
                        EvaluateInitialElements(); 
                }
                

                这篇关于如何在“绑定时间"获取 ListBox 中项目的 ListBoxItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)
                WPF ListBox not updating with the ItemsSource(WPF ListBox 未使用 ItemsSource 更新)
                Problem getting list box items added through jquery in code behind(在后面的代码中通过 jquery 添加列表框项目时出现问题)
                Items in ObservableCollectionlt;stringgt; do not update when bound to a WPF ListBox(ObservableCollectionlt;stringgt; 中的项目绑定到 WPF ListBox 时不更新)
                Selected item in list box is null(列表框中的选定项为空)
                ASP.NET: Listbox datasource and databind(ASP.NET:列表框数据源和数据绑定)

                        <tbody id='QpH4A'></tbody>
                    1. <i id='QpH4A'><tr id='QpH4A'><dt id='QpH4A'><q id='QpH4A'><span id='QpH4A'><b id='QpH4A'><form id='QpH4A'><ins id='QpH4A'></ins><ul id='QpH4A'></ul><sub id='QpH4A'></sub></form><legend id='QpH4A'></legend><bdo id='QpH4A'><pre id='QpH4A'><center id='QpH4A'></center></pre></bdo></b><th id='QpH4A'></th></span></q></dt></tr></i><div id='QpH4A'><tfoot id='QpH4A'></tfoot><dl id='QpH4A'><fieldset id='QpH4A'></fieldset></dl></div>

                      <tfoot id='QpH4A'></tfoot>
                        <bdo id='QpH4A'></bdo><ul id='QpH4A'></ul>

                        <small id='QpH4A'></small><noframes id='QpH4A'>

                      • <legend id='QpH4A'><style id='QpH4A'><dir id='QpH4A'><q id='QpH4A'></q></dir></style></legend>