Есть ли способ передать ребенку весь класс родительского контроля коллекции (в моем случае ListBox) в Command в ViewModel? Я могу передать любое значение «IsChecked», «AttachmentId» или «Name». Все три свойства являются частью класса «Присоединение». «AttachmentLst» (элемент источника ListBox содержит элементы «Attachment». Я хотел бы передать весь класс в свою команду. Ниже приведен рабочий код для передачи только одного свойства, в данном случае «AttachmentId». Как передать «Приложение» в Команда?Передача элемента (всего класса) списка родительского контроля в команду
<telerik:RadListBox telerik:StyleManager.Theme="Windows8" Name="lstAttachments" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" ItemsSource="{Binding AttachmentLst}">
<telerik:RadListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsChecked}" Command="{Binding ElementName=lstAttachments, Path=DataContext.AttachmentChecked}" CommandParameter="{Binding AttachmentId}" Content="Test" />
<Label Content="{Binding AttachmentId}" FontSize="12"></Label>
<Label Content="{Binding Name}" FontSize="12"></Label>
</StackPanel>
</DataTemplate>
</telerik:RadListBox.ItemTemplate>
</telerik:RadListBox>
ViewModel
public ObservableCollection<Attachment> AttachmentLst
{
get { return _attachmentLst; }
set { SetProperty(ref _attachmentLst, value); }
}
#endregion
#region Commands
public ICommand AttachmentChecked
{
get
{
return _attachmentChecked ?? (_attachmentChecked = new CommandHandlerWithParam(obj => ExecuteAttachmentChecked(obj), CanExecuteAttachmentChecked()));
}
}
private void ExecuteAttachmentChecked(object obj)
{
}
private bool CanExecuteAttachmentChecked()
{
return true;
}
приятно, спасибо – lucas
@ mauro21pl ваш прием. –