WPF ListBox ScrollIntoView 无效的问题

huangbochn 2017-05-06 09:46:59
窗体就一个Listbox,但是自动滚动无效,不会自动滚动到最后一行.
代码如下
private int a = 0;
private void test(object sender, EventArgs e)
{
string result = "分组代码未执行";

try
{
a += 1;
result=a.ToString();
}
catch (Exception ex)
{
result = ex.Message + "@" + System.DateTime.Now.ToString();
}
finally
{
Application.Current.Dispatcher.Invoke(new Action(delegate
{
gruopReport.Items.Add(result);
//var item = gruopReport.Items[updateReport.Items.Count - 1];
gruopReport.ScrollIntoView(gruopReport.Items[updateReport.Items.Count - 1]);
}));
}
}
...全文
361 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
exception92 2017-05-08
  • 打赏
  • 举报
回复
ScrollIntoView 的参数为 绑定到ListBoxItem上的实体对象,要把类似:
Entity entity = lb.Items[0] as Entity;
中的entity 作为参数传递进去。
exception92 2017-05-08
  • 打赏
  • 举报
回复
怎么会就一个listbox, gruopReport updateReport 这是几个ListBox? 你能保证updateReport 的Items 与gruopReport 的Items一致
huangbochn 2017-05-08
  • 打赏
  • 举报
回复
引用 2 楼 duanzi_peng 的回复:
怎么会就一个listbox, gruopReport updateReport 这是几个ListBox? 你能保证updateReport 的Items 与gruopReport 的Items一致
引用 2 楼 duanzi_peng 的回复:
怎么会就一个listbox, gruopReport updateReport 这是几个ListBox? 你能保证updateReport 的Items 与gruopReport 的Items一致
大哥,我错了.我检查几遍都没发现这个问题.原来是传递times.count时弄反了.所以无效.谢谢您! PS:确实是2个listbox,我是为了简化问题,去掉了一个listbox的代码.
huangbochn 2017-05-07
  • 打赏
  • 举报
回复
自己顶一下,不知道是不是哪里描述不清楚?

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧