I have defined a model as follows:
public class UserDetails
{
public int Id { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public List<Transport> TransportModel { get; set; }
}
Based on the above model, I have instantiated a list that contains hard coded values for testing purposes.
Further, I am dynamically populating buttons based on the TransportModel values on a XAML page as follows:
StackLayout stack = new StackLayout();
foreach (var t in user.TransportModel)
{
// Here I am looping to access data in the TransportModel
Button btn = new Button();
btn.Text = t.Name;
btn.SetBinding(Button.CommandProperty, new Binding("ShowCommandParameter"));
btn.CommandParameter = user.TransportModel; // if this correct ?
stack.Children.Add(btn);
}
And I have the following ViewModel:
public TransportViewModel()
{
ShowCommandParameter = new Command<UserDetails>(Show);
}
public void Show(UserDetails param)
{
// I want to access properties of TransportModel here..
}
The issue that I am having is that I want to pass two parameters in the CommandParameter. And I want to access these values within the Show method.
Could someone please help me on this ? I'm totally stuck.
btn.CommandParameter = t;? Then how do I access it within the methodShow?