I have simple Xamarin forms(5.0.0.2012) application. It contains a XAML page and a corresponding view model.
I have the following SearchBar element in the XAML file:
<SearchBar x:Name="searchBar"
HorizontalOptions="Fill"
VerticalOptions="CenterAndExpand"
Placeholder="Search vacancies..."
SearchCommand="{Binding PerformSearchCommand}"
SearchCommandParameter="{Binding Text, Source={x:Reference searchBar}}"/>
I have the following public Command property and static method in the view model:
public class SearchViewModel : INotifyPropertyChanged
{
public ICommand PerformSearchCommand => new Command(PerformSearch);
public event PropertyChangedEventHandler PropertyChanged;
private static void PerformSearch()
{
var i = 10;
i++;
}
When the search icon is clicked in the SearchBar. The PerformSearch() method is executed as expected. However, if I change the code to the following, the PerformSearch() method is no longer called.
public class SearchViewModel : INotifyPropertyChanged
{
public ICommand PerformSearchCommand = new Command(PerformSearch);
public event PropertyChangedEventHandler PropertyChanged;
private static void PerformSearch()
{
var i = 10;
i++;
}
I need to be able to use '=' approach to initialise the command in the constructor to pass in a non static method to execute. I have tested this issue on an android emulator. Is this a Xamarin bug?