【问题标题】:Many entries with OnItemsChanged(), how to delete old entries许多带有 OnItemsChanged() 的条目,如何删除旧条目
【发布时间】:2015-06-15 15:25:16
【问题描述】:

我是 xaml 的新手。条目被添加到滚动视图中并随着事件的变化而变化。有许多条目被记录导致内存消耗。如何删除之前输入的条目。那些删除的条目也不应该出现在滚动视图中。提前致谢。

这里是 xaml

<local:ScrollingLV x:Name="LogView" Width="300" Height="100"   Margin="10,0,10,10" ItemsSource="{Binding LogMsg}">

这是添加到滚动视图的代码

public partial class ScrollingLV : ListView
{
    protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        if (e.NewItems != null)
        {
            int iCount = e.NewItems.Count;
            if (iCount > 0)
            {
                this.ScrollIntoView(e.NewItems[iCount - 1]);
            }
        }

       base.OnItemsChanged(e);
    }
}

【问题讨论】:

  • 如何删除ListView中的条目。我已使用此代码删除,但它不起作用。使用 NotifyCollectionsChangedEventArgs。 e.OldItems.Clear()

标签: c# wpf xaml


【解决方案1】:

如果你使用 ObservableCollection,它就像从列表视图中删除一个项目一样简单

例如你可以参考这个msdn条目https://msdn.microsoft.com/en-us/library/ms748365(v=vs.110).aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 2021-10-14
    • 2016-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多