Home > Net >  XAML Binding - Cannot access array item
XAML Binding - Cannot access array item

Time:08-20

I'm trying to bind a property via MVVM pattern.

The payload is something like that:

{
    "QualificationSummary": "For all positions individuals must have IT-related experience...",
    "PositionRemuneration": [
        {
            "MinimumRange": "62639.0",
            "MaximumRange": "137348.0",
            "RateIntervalCode": "PA"
        }
    ]
}

I Tried this, but did nor worked.

<Label>
    <Label.Text>
       <MultiBinding StringFormat="{}{0}{1}">
           <Binding Path="PositionRemuneration[MinimumRange]"/>
           <Binding Path="PositionRemuneration[MaximumRange]"/>
        </MultiBinding>
      </Label.Text>
</Label>

Any clues?

CodePudding user response:

After spend some time understanding the problem, that's the solution.

The c# class:

public Positionlocation[] PositionLocation { get; set; }

 public class Positionlocation
    {
        public string LocationName { get; set; }
        public string CountryCode { get; set; }
        public string CountrySubDivisionCode { get; set; }
        public string CityName { get; set; }
        public float Longitude { get; set; }
        public float Latitude { get; set; }
    }

and to access the property:

<Binding Path="MatchedObjectDescriptor.PositionLocation[0].LocationName"/>

CodePudding user response:

If your Binding Context is setup properly, you should be able to bind to your property as easily as:

<Binding Path="PositionRemuneration.MinimumRange"/>
  • Related