Compare commits

...

1 Commits

Author SHA1 Message Date
qhy040404
3fa4281a0a show not found if no result 2024-03-16 19:37:18 +08:00
5 changed files with 30 additions and 17 deletions

View File

@@ -48,7 +48,7 @@ internal sealed partial class AutoSuggestTokenBox : TokenizingTextBox
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
sender.ItemsSource = AvailableTokens.Values.Where(q => q.Value.Contains(Text, StringComparison.OrdinalIgnoreCase));
sender.ItemsSource = AvailableTokens.Values.WhereOrDefault(q => q.Value.Contains(Text, StringComparison.OrdinalIgnoreCase), [SearchToken.NotFound]);
}
}

View File

@@ -7,6 +7,8 @@ namespace Snap.Hutao.Control.AutoSuggestBox;
internal sealed class SearchToken
{
public static readonly SearchToken NotFound = new(SearchTokenKind.None, SH.ControlAutoSuggestBoxNotFoundValue);
public SearchToken(SearchTokenKind kind, string value, Uri? iconUri = null, Uri? sideIconUri = null, Color? quality = null)
{
Value = value;

View File

@@ -123,4 +123,9 @@ internal static partial class EnumerableExtension
{
return string.Join(separator, collection);
}
public static IEnumerable<TSource> WhereOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate, IEnumerable<TSource> defaultValue)
{
return source.Where(predicate).Any() ? source : defaultValue;
}
}

View File

@@ -144,6 +144,9 @@
<data name="ContentDialogSavePrimaryButtonText" xml:space="preserve">
<value>Save</value>
</data>
<data name="ControlAutoSuggestBoxNotFoundValue" xml:space="preserve">
<value>No results found</value>
</data>
<data name="ControlImageCachedImageInvalidResourceUri" xml:space="preserve">
<value>Invalid Uri</value>
</data>

View File

@@ -144,6 +144,9 @@
<data name="ContentDialogSavePrimaryButtonText" xml:space="preserve">
<value>保存</value>
</data>
<data name="ControlAutoSuggestBoxNotFoundValue" xml:space="preserve">
<value>未找到结果</value>
</data>
<data name="ControlImageCachedImageInvalidResourceUri" xml:space="preserve">
<value>无效的 Uri</value>
</data>