Merge pull request #754 from Flow-Launcher/fix_converter_casting_null

Dev branch: fix issue with converters casting to null values
This commit is contained in:
Jeremy Wu 2021-10-14 09:13:37 +11:00 committed by GitHub
commit 13917d177c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 9 deletions

View file

@ -16,12 +16,10 @@ namespace Flow.Launcher.Converters
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var hotkeyNumber = int.MaxValue;
if (value is ListBoxItem listBoxItem)
{
ListBox listBox = ItemsControl.ItemsControlFromItemContainer(listBoxItem) as ListBox;
if (value is ListBoxItem listBoxItem
&& ItemsControl.ItemsControlFromItemContainer(listBoxItem) is ListBox listBox)
hotkeyNumber = listBox.ItemContainerGenerator.IndexFromContainer(listBoxItem) + 1;
}
return hotkeyNumber <= MaxVisibleHotkeys ? Visibility.Visible : Visibility.Collapsed;
}

View file

@ -8,11 +8,9 @@ namespace Flow.Launcher.Converters
{
public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
{
if (value is ListBoxItem listBoxItem)
{
ListBox listBox = ItemsControl.ItemsControlFromItemContainer(listBoxItem) as ListBox;
if (value is ListBoxItem listBoxItem
&& ItemsControl.ItemsControlFromItemContainer(listBoxItem) is ListBox listBox)
return listBox.ItemContainerGenerator.IndexFromContainer(listBoxItem) + 1;
}
return 0;
}