0
votes

I'm a newbie in these subjects of Xamarin, but have been able to built a good amount amount of features in a personal project to a local Bodyboarding Association that I'm doing for learning purposes. But got stuck in one Panel that its making me go crazy.

You can see the attach image that represents the objective of this panel and most of it, is done so far.

The objective: Is for the user to insert Numeric values in "Entry A", then clicks "Button A" so that each one of the items gets added to the right List "ListView B". The ListView A is dynamic but has, in max, five elements and all of the Entries must be available for fast filling of the user.

The problem: Im not being able to make the button to add values into that inner ListView because i'm not able to have the ID of it in the code-behind. Im using Command & CommandParameter in a MVVM structure.

Is the usage of nested ListView possible this way?

Thank you.

enter image description here

1
Why do you need nested listviews? - FreakyAli
I cannot justify that due to lack of knowledge, but, from the first hand, seemed like the best way of relate two lists when i need data entries in the inner List. - Claudio Domingos
you should never nest ListViews - Jason
So, what should be the correct way of doing this Page ? - Claudio Domingos
The best way to achieve this is to create a reusable component. - Skin

1 Answers

0
votes

If your outer list items type is something like this

public class OuterListItem{
 public string EntryAText { get; set; }
 public ObservableCollection<string> InnerListItems { get; set; }
}

On your ViewModel you could have something like this

ICommand ButtonCommand = new Command<OuterListItem>((oli) => {
  oli.InnerListItems.Add(oli.EntryAText);
  oli.EntryAText = String.Empty;
});

and last on your XAML add an x:Name to your page and the button would look like this

<Button Command="{Binding ButtonCommand, Source={x:Reference PageName}}" CommandParameter="{Binding .}"></Button>

You need the x:Name and Source attribute to reference a command which is not implemented within the list item.

This way you do not need any ID.