Xamarin Form: How to bind Command from ViewModel to XAML
<p>I am trying to bind a command to a button in Xaml. I can bind a property declared in ViewModel and seeing it to change the color of the button's background. Using the same way adding the Command to the button, the button didn't fire the command when I clicked on it. </p>

<p>My ViewModel Command Property</p>

<pre><code>    public Color Color
    {
        get
        {
            return Color.Teal;
        }
    }

    public ICommand OpenFileCommand = new Command((object obj) =&gt; { 
        Task.Run(() =&gt;
        {
              var pickFileTask = CrossFilePicker.Current.PickFile();
              var data = pickFileTask.Result;
              //OpenDocument(data.FileName, data.DataArray);
        });
    });
</code></pre>

<p>The Xaml Part : </p>

<pre><code>&lt;!-- Left Panel --&gt; 
            &lt;StackLayout x:Name="leftStack" Orientation="Vertical" BackgroundColor="Transparent"&gt;
                &lt;Button  
                    x:Name="btnOpen"
                    BackgroundColor="{Binding Color}" 
                    Command="{Binding OpenFileCommand}"
                    Image="addfile"
                    HorizontalOptions="CenterAndExpand"
                    VerticalOptions="CenterAndExpand"  
                    WidthRequest="40" 
                    HeightRequest="40"&gt;
                &lt;/Button&gt;
</code></pre>

<p>If I bind the command in code, it will execute the OpenFileCommmand in my view model class :</p>

<pre><code>btnOpen.Command = viewModel.OpenFileCommand;
</code></pre>