After such a binding, it is impossible to focus on the search bar. When tapped nothing happens. After calling ChangeCanExecute()
SearchBar's property IsEnabled
changes to true
and that's all.
Can't figure out where the error is.
Xamarin.Forms version: 4.8.0.1451
.NET Standard 2.1
My view:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:SearchBarTest"
x:Class="SearchBarTest.MainPage">
<ContentPage.BindingContext>
<local:TestViewModel/>
</ContentPage.BindingContext>
<StackLayout>
<SearchBar SearchCommand="{Binding TestCommand}"/>
</StackLayout>
</ContentPage>
View model:
internal class TestViewModel
{
private bool isInitialized;
public Command TestCommand { get; }
public TestViewModel()
{
Task.Run(() =>
{
Thread.Sleep(5000);
isInitialized = true;
Debug.WriteLine($">>> Initialized: {isInitialized}");
TestCommand.ChangeCanExecute();
});
TestCommand = new Command(() =>
{
Debug.WriteLine(">>> Command invoked.");
}, () => isInitialized);
}
}