Reputation: 1251
I'm new to MVVM so please excuse my idiocy.
I have a grid containing 6 instances of a custom usercontrol.
userCtrl1, userCtrl2, userCtrl3, userCtrl4, and so on..
I created a viewModel class called 'playerInfo' and set the usercontrol's datacontext.
My question is how to reference the name in the viewmodel.
I need to get the index ( userCtrl "4" ) to reference a list in a 3rd party library I'm working with.
Sounds wierd, and I don't know if this violates the MVVM pattern.
Many thanks in advanced!
Upvotes: 2
Views: 1633
Reputation: 34275
Alternative solution (if "index to reference a list" is equal to userCtrl# number and layout is not too complex):
ObservableCollection<PlayerInfo> Players
property in the view model.ItemsControl
into your view and bind to Players
. If you want to customize layout, you can change its ItemsPanel
template.DataTemplate
and set its DataType
to {x:Type PlayerInfo}
. Put your user control into it and bind to {Binding}
.Players.IndexOf
method.Upvotes: 2