@ -1403,74 +1403,75 @@ namespace Avalonia.Controls
// Indicate that filtering is ongoing
_f ilterInAction = true ;
if ( _ items = = null )
try
{
ClearView ( ) ;
return ;
}
if ( _ items = = null )
{
ClearView ( ) ;
return ;
}
// Cache the current text value
string text = Text ? ? string . Empty ;
// Cache the current text value
string text = Text ? ? string . Empty ;
// Determine if any filtering mode is on
bool stringFiltering = TextFilter ! = null ;
bool objectFiltering = FilterMode = = AutoCompleteFilterMode . Custom & & TextFilter = = null ;
List < object > items = _ items ;
// Determine if any filtering mode is on
bool stringFiltering = TextFilter ! = null ;
bool objectFiltering = FilterMode = = AutoCompleteFilterMode . Custom & & TextFilter = = null ;
// cache properties
var textFilter = TextFilter ;
var itemFilter = ItemFilter ;
var _ newViewItems = new Collection < object > ( ) ;
// if the mode is objectFiltering and itemFilter is null, we throw an exception
if ( objectFiltering & & itemFilter is null )
{
// indicate that filtering is not ongoing anymore
_f ilterInAction = false ;
_ cancelRequested = false ;
throw new Exception (
"ItemFilter property can not be null when FilterMode has value AutoCompleteFilterMode.Custom" ) ;
}
List < object > items = _ items ;
foreach ( object item in items )
{
// Exit the fitter when requested if cancellation is requested
if ( _ cancelRequested )
// cache properties
var textFilter = TextFilter ;
var itemFilter = ItemFilter ;
var _ newViewItems = new Collection < object > ( ) ;
// if the mode is objectFiltering and itemFilter is null, we throw an exception
if ( objectFiltering & & itemFilter is null )
{
return ;
throw new Exception (
"ItemFilter property can not be null when FilterMode has value AutoCompleteFilterMode.Custom" ) ;
}
bool inResults = ! ( stringFiltering | | objectFiltering ) ;
if ( ! inResults )
foreach ( object item in items )
{
if ( stringFiltering )
// Exit the fitter when requested if cancellation is requested
if ( _ cancelRequested )
{
inResults = textFilter ! ( text , FormatValue ( item ) ) ;
return ;
}
else if ( objectFiltering )
bool inResults = ! ( stringFiltering | | objectFiltering ) ;
if ( ! inResults )
{
inResults = itemFilter ! ( text , item ) ;
if ( stringFiltering )
{
inResults = textFilter ! ( text , FormatValue ( item ) ) ;
}
else if ( objectFiltering )
{
inResults = itemFilter ! ( text , item ) ;
}
}
}
if ( inResults )
{
_ newViewItems . Add ( item ) ;
if ( inResults )
{
_ newViewItems . Add ( item ) ;
}
}
}
_ view ? . Clear ( ) ;
_ view ? . AddRange ( _ newViewItems ) ;
// Clear the evaluator to discard a reference to the last item
_ valueBindingEvaluator ? . ClearDataContext ( ) ;
_ view ? . Clear ( ) ;
_ view ? . AddRange ( _ newViewItems ) ;
// indicate that filtering is not ongoing anymore
_f ilterInAction = false ;
_ cancelRequested = false ;
// Clear the evaluator to discard a reference to the last item
_ valueBindingEvaluator ? . ClearDataContext ( ) ;
}
finally
{
// indicate that filtering is not ongoing anymore
_f ilterInAction = false ;
_ cancelRequested = false ;
}
}
/// <summary>