Don't change selected index unless collection is not empty

This commit is contained in:
弘韬 张 2020-11-14 12:04:10 +08:00
parent e625c192ee
commit e34a52c74e

View file

@ -137,8 +137,16 @@ namespace Flow.Launcher.ViewModel
{ {
var newResults = NewResults(newRawResults, resultId); var newResults = NewResults(newRawResults, resultId);
// update UI in one run, so it can avoid UI flickering lock (_collectionLock)
Results.Update(newResults); {
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/5ff71969-f183-4744-909d-50f7cd414954/binding-a-tabcontrols-selectedindex-not-working?forum=wpf
// fix selected index flow
if (Results.Count > 0)
SelectedIndex = 0;
// update UI in one run, so it can avoid UI flickering
Results.Update(newResults);
}
if (Visbility != Visibility.Visible && Results.Count > 0) if (Visbility != Visibility.Visible && Results.Count > 0)
{ {
@ -159,12 +167,14 @@ namespace Flow.Launcher.ViewModel
{ {
var newResults = NewResults(resultsForUpdates); var newResults = NewResults(resultsForUpdates);
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/5ff71969-f183-4744-909d-50f7cd414954/binding-a-tabcontrols-selectedindex-not-working?forum=wpf
// fix selected index flow
SelectedIndex = 0;
lock (_collectionLock) lock (_collectionLock)
{ {
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/5ff71969-f183-4744-909d-50f7cd414954/binding-a-tabcontrols-selectedindex-not-working?forum=wpf
// fix selected index flow
if (Results.Count > 0)
SelectedIndex = 0;
Results.Update(newResults); Results.Update(newResults);
} }
@ -172,6 +182,7 @@ namespace Flow.Launcher.ViewModel
{ {
case Visibility.Collapsed when Results.Count > 0: case Visibility.Collapsed when Results.Count > 0:
Margin = new Thickness { Top = 8 }; Margin = new Thickness { Top = 8 };
SelectedIndex = 0;
Visbility = Visibility.Visible; Visbility = Visibility.Visible;
break; break;
case Visibility.Visible when Results.Count == 0: case Visibility.Visible when Results.Count == 0: