Как передать значение свойства в IMvxCommand из .axml в Xamarin.Android MVVMCross - PullRequest
0 голосов
/ 02 апреля 2019

Я пытаюсь передать значение свойства в IMvxCommand из привязки, реализованной в XML

Вот XML-привязка

<Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button Label"
        android:textSize="14sp"
        android:letterSpacing=".08"
        android:lineSpacingMultiplier="1.12"
        android:layout_marginTop="10dp"
        card_view:MvxBind="Click ItemSelectedCommand , CommandParameter = Location.Id; Typeface StringToFont('Effra_Rg')"/>  

И ниже команда

Я всегда получаю значение как String "Location.Id" в param.

Я что-то не так делаю или есть альтернатива для достижения этой цели.

Редактировать 1:

Модель местоположения

 public class Location
{
    [JsonProperty("id")]
    public string Id { get; set; }

    [JsonProperty("type")]
    public string Type { get; set; }

    [JsonProperty("name")]
    public string Name { get; set; }

    [JsonProperty("latitude")]
    public double Latitude { get; set; }

    [JsonProperty("longitude")]
    public double Longitude { get; set; }

    [JsonProperty("location")]
    public LocationDetail LocationDetail { get; set; }
}

Ниже представлена ​​модель вида:

public class GenericLocationViewModel : MvxViewModel
{
    public Location Location { get; set; }

    public LocationExtension LocationExtension { get; set; }
    private MainViewModel _mainViewModel;
    private readonly IMvxNavigationService _navigationService;

    public GenericLocationViewModel(Location location, IMvxNavigationService navigationService, LocationType locationType = LocationType.UrgentCare)
    {
        Location = location;
        LocationExtension = new LocationExtension(location, locationType);
        _navigationService = navigationService ?? throw new ArgumentNullException(nameof(navigationService));
        _mainViewModel = new MainViewModel(_navigationService);
    }

    public IMvxCommand ItemSelectedCommand
    {
        get
        {
            return new MvxCommand<String>(async param =>
            {
                if (param==null) // Here getting value as "Location.Id" but I am expecting the value of Id from Location model.
                {
                    //Implementation.
                }
            });
        }
    }
}
...