Browse Source
Merge pull request #6536 from Takoooooo/autocompletebox-nre-fix
Fix AutoCompleteBox NRE
pull/6552/head
Jumar Macato
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
25 additions and
1 deletions
-
src/Avalonia.Controls/AutoCompleteBox.cs
-
tests/Avalonia.Controls.UnitTests/AutoCompleteBoxTests.cs
|
|
|
@ -2094,7 +2094,21 @@ namespace Avalonia.Controls |
|
|
|
bool inResults = !(stringFiltering || objectFiltering); |
|
|
|
if (!inResults) |
|
|
|
{ |
|
|
|
inResults = stringFiltering ? TextFilter(text, FormatValue(item)) : ItemFilter(text, item); |
|
|
|
if (stringFiltering) |
|
|
|
{ |
|
|
|
inResults = TextFilter(text, FormatValue(item)); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (ItemFilter is null) |
|
|
|
{ |
|
|
|
throw new Exception("ItemFilter property can not be null when FilterMode has value AutoCompleteFilterMode.Custom"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
inResults = ItemFilter(text, item); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (view_count > view_index && inResults && _view[view_index] == item) |
|
|
|
|
|
|
|
@ -105,6 +105,16 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Custom_FilterMode_Without_ItemFilter_Setting_Throws_Exception() |
|
|
|
{ |
|
|
|
RunTest((control, textbox) => |
|
|
|
{ |
|
|
|
control.FilterMode = AutoCompleteFilterMode.Custom; |
|
|
|
Assert.Throws<Exception>(() => { control.Text = "a"; }); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Text_Completion_Via_Text_Property() |
|
|
|
{ |
|
|
|
|