Given this object
class Contact
{
public IEnumerable<Person> People { get; }
public string PhoneNumber { get; }
}
class Person
{
public string MobileNumber { get; }
}
And the following layout
<Contact>
<PhoneNumber/>
<SinglePerson.MobileNumber/>
<People>
<MobileNumber />
</People>
<Contact>
What I'd like to do is hide the People element when there is only one person, and show the SinglePerson.Mobile number element instead.
Hiding is fairly easy:
<Style.Triggers>
<DataTrigger Binding="{Binding Path=People.Count}" Value="1">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
Showing is slightly more tricky:
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=People.Count}" Value="1">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
The thing that I can't work out how to do is to bind the <SinglePerson.MobileNumber>
Text to the first person in the People list. I've tried variants of "{Binding People[0].MobilePhone}", but that doesn't work.
Is it even possible?