fix selected item doesn't always be the first item issue.

Method: Not only update selected index, but also update selected item when adding results.
This commit is contained in:
弘韬 张 2020-11-28 13:25:49 +08:00
parent 05aa7062d7
commit 813e9b5439
2 changed files with 5 additions and 11 deletions

View file

@ -9,7 +9,7 @@
d:DataContext="{d:DesignInstance vm:ResultsViewModel}"
MaxHeight="{Binding MaxHeight}"
SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}"
SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
HorizontalContentAlignment="Stretch" ItemsSource="{Binding Results}"
Margin="{Binding Margin}"
Visibility="{Binding Visbility}"

View file

@ -144,11 +144,10 @@ namespace Flow.Launcher.ViewModel
{
// 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);
SelectedItem = newResults[0];
}
if (Visbility != Visibility.Visible && Results.Count > 0)
@ -176,9 +175,11 @@ namespace Flow.Launcher.ViewModel
{
// 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;
Results.Update(newResults, token);
SelectedItem = newResults[0];
}
switch (Visbility)
@ -321,13 +322,6 @@ namespace Flow.Launcher.ViewModel
editTime++;
return;
}
else if (editTime < 15 || newItems.Count < 50)
{
ClearItems();
AddRange(newItems);
editTime++;
return;
}
Clear();
BulkAddRange(newItems);