-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null check for autocomplete box #3741
Labels
Waiting on feedback
Additional information is needed. Stale items with this label may be closed.
Comments
AmeerMansour
added
bug
evaluation required
Items is pending review or evaluation by the team
labels
Dec 13, 2024
@AmeerMansour I can't reproduce your problem. Can you share more information about your project and/or check if you have implemented the <Window x:Class="MDIX3741.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MDIX3741"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="800"
Height="450"
Style="{StaticResource MaterialDesignWindow}"
mc:Ignorable="d">
<materialDesign:AutoSuggestBox Margin="5"
VerticalAlignment="Center"
materialDesign:HintAssist.Hint="Value"
materialDesign:TextFieldAssist.HasClearButton="True"
Style="{StaticResource MaterialDesignOutlinedAutoSuggestBox}"
Suggestions="{Binding Suggestions}"
Text="{Binding MyValue, UpdateSourceTrigger=PropertyChanged}">
<materialDesign:AutoSuggestBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding .}" />
</DataTemplate>
</materialDesign:AutoSuggestBox.ItemTemplate>
</materialDesign:AutoSuggestBox>
</Window> Code behind: public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new MainViewModel();
}
}
public partial class MainViewModel : ObservableObject
{
private static readonly List<string> _allSuggestions = ["1", "11", "112", "1333", "444"];
[ObservableProperty]
private string _myValue;
partial void OnMyValueChanged(string value)
{
if (string.IsNullOrEmpty(value))
{
Suggestions = _allSuggestions;
return;
}
Suggestions = _allSuggestions.Where(x => x.Contains(value, StringComparison.InvariantCultureIgnoreCase))
.ToList();
}
private IReadOnlyList<string> _suggestions;
public IReadOnlyList<string> Suggestions
{
get => _suggestions;
set => SetProperty(ref _suggestions, value);
}
} Make sure to install the CommunityToolkit.Mvvm to get this code to work. |
@AmeerMansour did this answer your question or does your problem persist? |
corvinsz
added
Waiting on feedback
Additional information is needed. Stale items with this label may be closed.
and removed
bug
evaluation required
Items is pending review or evaluation by the team
labels
Jan 8, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Waiting on feedback
Additional information is needed. Stale items with this label may be closed.
Bug explanation
I start type in the autocomplete boxthen when I select one of the suggestions it crashes
this is my xmal
and it crash here for nor selecteditem being null
Version
5.1
The text was updated successfully, but these errors were encountered: