OSDN Git Service

ListView.set_TopItem内部でNullReferenceExceptionが発生する問題に対処
authorKimura Youichi <kim.upsilon@bucyou.net>
Sat, 12 Aug 2017 19:03:46 +0000 (04:03 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 12 Aug 2017 19:12:50 +0000 (04:12 +0900)
原因は未だ不明なものの、内部で ListView.get_TopItem が null を返していると考えられる。
例外が発生した場合は EnsureVisible を二回呼び出してスクロールする。

https://osdn.net/ticket/browse.php?group_id=6526&tid=36219

Fixes: 1da38617 ("発言一覧の表示位置の固定に ListView.TopItem を使用する")

OpenTween/Tween.cs

index 15daa76..2310f11 100644 (file)
@@ -1630,7 +1630,18 @@ namespace OpenTween
                 case ScrollLockMode.FixedToItem:
                     var topIndex = listScroll.TopItemStatusId != null ? tab.IndexOf(listScroll.TopItemStatusId.Value) : -1;
                     if (topIndex != -1)
-                        listView.TopItem = listView.Items[topIndex];
+                    {
+                        var topItem = listView.Items[topIndex];
+                        try
+                        {
+                            listView.TopItem = topItem;
+                        }
+                        catch (NullReferenceException)
+                        {
+                            listView.EnsureVisible(listView.VirtualListSize - 1);
+                            listView.EnsureVisible(topIndex);
+                        }
+                    }
                     break;
                 case ScrollLockMode.None:
                 default: