WPF列表框不与的ItemsSource更新 [英] WPF ListBox not updating with the ItemsSource

查看:163
本文介绍了WPF列表框不与的ItemsSource更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么,我相信应该是简单的双向数据绑定在WPF设置,但在列表框中(目标)没有更新的集合改变。

I have what I believe should be simple two-way databinding in WPF setup, but the listbox (target) is not updating as the collection changes.

我设置这个的ItemsSource ListBox的编程方式:

I'm setting this ItemsSource of the ListBox programmatically:

lstVariable_Selected.ItemsSource = m_VariableList;

和ListBox中声明如下:

And the ListBox is declared as follows:

           <ListBox Margin="5" Name="lstVariable_Selected">
              <ListBox.ItemsPanel>
                 <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal"/>
                 </ItemsPanelTemplate>
              </ListBox.ItemsPanel>
              <ListBox.ItemTemplate>
                 <DataTemplate>
                    <Border BorderBrush="Gray" BorderThickness="1" Margin="0">
                       <TextBlock FontSize="25" Text="{Binding Path=Name}" />
                    </Border>
                 </DataTemplate>
              </ListBox.ItemTemplate>
           </ListBox>

当我最初设置的ItemsSource,列表框(这是不可见的时间)得到它的项目设置。但是,如果我去查看列表框,更新似乎停止在这一点上。

When I initially set the ItemsSource, the ListBox (which is not visible at the time) gets its items set. However, if I go view the ListBox, updates seem to stop at that point.

我就可以从m_VariableList集合中删除某个项目,并且不从列表框中消失。同样,如果我添加一个,它不会出现。

I can then remove an item from the m_VariableList collection, and it does not disappear from the ListBox. Likewise, if I add one, it doesn't appear.

怎么办?

推荐答案

是您m_VariableList实施<一个href="http://msdn.microsoft.com/en-us/library/system.collections.specialized.inotifycollectionchanged.aspx">INotifyCollectionChanged?如果它不是一个ObservableCollection,然后改到它的内容不会自动反映在UI中。

Is your m_VariableList implementing INotifyCollectionChanged? If it's not an ObservableCollection, then changes to it's contents will not automatically be reflected in the UI.

这篇关于WPF列表框不与的ItemsSource更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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