当前位置:编程学习 > C#/ASP.NET >>

WPF中ListBox频繁添加条目会闪屏,如何解决? 初学 请指教

我在WPF中使用ListBox绑定数据,在频繁添加条目时会闪屏,请问如何解决? --------------------编程问答-------------------- 应该不会出现这样的情况吧!是不是你的代码在添加数据的时候做了其他的操作?贴出你的代码看看。 --------------------编程问答-------------------- 我在通信线程里接收到数据的时候添加的数据,在主线程里添加的事件,程序大概是这样的

 public void delegate UpdateMsgListDelegate(string str);
public event UpdateMsgListDelegate updateMsg;
 MainWindow()
{
    this.updateMsg += new UpdateMsgListDelegate(OnRecvdMsg);
}

private void OnRecvdMsg(string str)
{
    if ( updateMsg != null )
    this.dispatch.BeginInvoke(AddMsg, str);
}

private void AddMsg(string str)
{
    BindList.Add(str);   //BindList 是ListBox1绑定的数据集
    ListBox1.selectIndex = BindList.count - 1;
    ListBox1.ScrollIntoView(ListBox1.selectItem); //我希望能够自动滚屏
}

--------------------编程问答-------------------- 以前做过,在绑定数据之前要使用liatBox1.BeginUpdate();绑定之后要使用ListBox1.EndUpdate() --------------------编程问答-------------------- 以后遇到问题第一反应就是google --------------------编程问答-------------------- 用ObservableCollection绑定,让它自动更新 --------------------编程问答-------------------- 为什么要让他update呢?直接添加
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,