Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

CommandParameter binding does not work

$
0
0

I am observing strange behavior when attempting to bind to a CommandParameter.

Although the IsEnabled binding works fine, the CommandParameter binding results in a null argument being passed to my delegate.
Note how both properties (IsEnabled and CommandParameter) both bind to the same SelectedContent property. As a result, I am almost certain that my binding is setup correctly.

XAML:

<Button Text="Edit" Grid.Row="2" Grid.Column="0"
        Command="{Binding Source={StaticResource Commands}, Path=Edit}"
        IsEnabled="{Binding Source={StaticResource ViewModel}, Path=SelectedContent.Value, Converter={StaticResource IsInstanceToBoolConverter}}"
        CommandParameter="{Binding Source={StaticResource ViewModel}, Path=SelectedContent.Value}"
        />

Commands:

public class Commands : ViewModelBase
{
    MessageBus _messagebus = MessageBus.Instance;

    public Commands()
    {
        Edit = new DelegateCommand(obj => _messagebus.Publish(Messages.REQUEST_EDIT, obj as string));
    }

    public ICommand Edit { get; private set; }
}

ViewModel:

public class ViewModel : ViewModelBase
{
    Content _selectedContent = null;
    public Content SelectedContent
    {
        get
        {
            return _selectedContent;
        }
        set
        {
            if (_selectedContent != value)
            {
                _selectedContent = value;
                OnPropertyChanged();
            }
        }
    }
}

}

Is this a bug?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>