. ViewModel ICommand Select ( - ), Button
Command="{Binding Select, ElementName="root"}"
ICommand,
CommandParameter="{Binding}"
(#/XAML ):
public class MyModel { public string Name {get;set;} }
public class MyViewModel
{
public ObservableCollection<MyModel> Models {get;set;}
public ICommand Select {get;set;}
}
<UserControl DataContext="{StaticResource MyViewModelInstance}" x:Name="root">
<ItemsControl ItemsSource="{Binding Models}">
<ItemsControl.ItemTemplate>
<ItemsPanelTemplate>
<Button Text="{Binding Name}"
Command="{Binding Select, ElementName="root"}"
CommandParameter="{Binding}"/>
</ItemsPanelTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</UserControl>
ItemsControl , MyModel . . ViewModel. , ICommand, MyModel, .
, ViewModels UserControl - . UserControl - , ViewModel, . UserControl. ItemsSource, UserControl, ItemsControl , ViewModel .