0

WinUI 3 Desktop WindowsAppSDK (1.2.230313)

I'm recieving a NullReferenceException on an AutoSuggestBox component when typing in it. When debugging, the breakpoints never hit their methods, and the application breaks with the following error image:

enter image description here

My View looks like this:

<AutoSuggestBox QueryIcon="Find" 
                                ItemsSource="{x:Bind AP.ViewModel.Entities, Mode=TwoWay}"
                                TextChanged="{x:Bind AP.ViewModel.AutoSuggestBox_TextChanged}"
                                SuggestionChosen="{x:Bind AP.ViewModel.AutoSuggestBox_SuggestionChosen}"
                                QuerySubmitted="{x:Bind AP.ViewModel.AutoSuggestBox_QuerySubmitted}"/>
  • I don't understand why this is marked as duplicate, but these (AutoSuggestBox_TextChanged, AutoSuggestBox_SuggestionChosen, AutoSuggestBox_QuerySubmitted) are methods right? AFAIK, you can't (the compiler won't let you) directly bind methods to events. You need to use [Behaviors](https://stackoverflow.com/a/40502513/2411960) for this. – Andrew KeepCoding Apr 01 '23 at 23:48
  • Best guess, but the ViewModel is probably null... thus it's a duplicate. – Erik Philips Apr 02 '23 at 02:21
  • I found the problem being the ViewModel.Entities was an empty/null observablecollection. Once I seeded it with info, things worked ok. The methods do bind when you declare the TypedEventHandler in the ViewModel, and bind them in the Presenter class. Stupid mistake – Keyboard_Kowboy Apr 03 '23 at 15:00

0 Answers0