Skip to content

Commit

Permalink
fix searchccombobox
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Aug 1, 2024
1 parent e674d83 commit 05381e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
3 changes: 0 additions & 3 deletions src/OneWare.Essentials/Controls/SearchComboBox.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@
</ControlTheme>
</Styles.Resources>

<Style Selector="ComboBoxItem:selected /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeControlHighlightLowBrush}"/>
</Style>
<Style Selector="ComboBoxItem:searchResult /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush3}"/>
</Style>
Expand Down
27 changes: 18 additions & 9 deletions src/OneWare.Essentials/Controls/SearchComboBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public int ResultIndex
set
{
_resultIndex = value;
if(value < 0)
{
ResultItem = null;
return;
}
ResultItem = ContainerFromIndex(value) as SearchComboBoxItem;
ScrollIntoView(value);
}
Expand Down Expand Up @@ -62,21 +67,25 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)

_searchBox!.TextChanged += (sender, args) =>
{
var item = Items.FirstOrDefault(x =>
x?.ToString()?.StartsWith(_searchBox.Text ?? string.Empty, StringComparison.OrdinalIgnoreCase)
?? x?.ToString()?.Contains(_searchBox.Text ?? string.Empty, StringComparison.OrdinalIgnoreCase)
?? false);

object? item = null;
if (!string.IsNullOrWhiteSpace(_searchBox.Text))
{
item = Items.FirstOrDefault(x =>
x?.ToString()?.StartsWith(_searchBox.Text ?? string.Empty, StringComparison.OrdinalIgnoreCase) ??
false);

item ??= Items.FirstOrDefault(x =>
x?.ToString()?.Contains(_searchBox.Text ?? string.Empty, StringComparison.OrdinalIgnoreCase) ??
false);
}

if (IsInteractive)
{
SelectedItem = item;
}
else
{
if (item != null)
{
ResultIndex = Items.IndexOf(item);
}
ResultIndex = Items.IndexOf(item);
}

_searchBox.Focus();
Expand Down

0 comments on commit 05381e0

Please sign in to comment.