【问题标题】:How can you scroll a ListBox to the bottom如何将 ListBox 滚动到底部
【发布时间】:2013-07-22 09:34:01
【问题描述】:

如何在 C# 中将列表框滚动到底部? ListBox 中的项目没有名称,这可能会使其更加困难。

【问题讨论】:

    标签: c# windows-phone-7 listbox windows-phone-8 windows-phone-7.8


    【解决方案1】:

    你可以这样做..

     listbox.ScrollIntoView(listbox.Items[listbox.Items.Count - 1]);
    

    【讨论】:

    • 这是一个列表框,不是滚动查看器。
    • 我真的很抱歉我犯的错误..hopw它会解决你的问题..
    • 它似乎几乎滚动到 ListBox 的末尾,但似乎在最后一项中途停止。
    【解决方案2】:

    在 C# 中:

    yourListBox.SelectedIndex = yourListBox.ItemsSource.Count();
    

    如果由于某种原因你没有Count,试试这个:

    public static int Count<TSource>(this IEnumerable<TSource> source)
    {
      if (source == null)
        throw new ArgumentNullException("source");
      ICollection collection = source as ICollection;
      if (collection != null)
        return collection.Count;
      int num = 0;
      foreach (TSource item in source)
          checked { ++num; }
      return num;
    }
    

    【讨论】:

    • 这会报错,说.Count没有定义,.Count没有扩展方法
    • @Newbie 将using System.Linq; 添加到文件顶部。
    • 我已经在使用 System.Linq;作为 Windows Phone 项目的默认语句
    • @newStackExchangeInstance 他不能直接使用yourListBox.Items.Count吗?
    • @anderZubi 如果不是 ICollection,则不会。
    猜你喜欢
    • 2012-02-06
    • 1970-01-01
    • 2020-09-24
    • 2010-10-28
    • 2013-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多