I've been using MVVM's RelayCommand with success to bind actions to XAML, but I'm having a small problem with my ItemsControl.
<ItemsControl ItemsSource="{Binding Devices}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Width="100" Margin="4" >
<Button Command="{Binding Path=SelectDeviceCommand}" >
<Grid>
<Image Source="img_small.png"></Image>
<Image Source="{Binding Path=Logo}" />
</Grid>
</Button>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
In my view model:
public RelayCommand SelectDeviceCommand { get; set; }
private ObservableCollection<Device> Devices;
Devices = CreateListOfDevices();
private void InitializeCommands()
{
SelectDeviceCommand = new RelayCommand((s) => MessageBox.Show(s.ToString()));
}
How do I define my SelectDeviceCommand in my view model in order to receive object that is bound to that item?
My SelectDeviceCommand is not even being called... (but that I guess is because I need to make my Device a mini-viewmodel and implement the SelectDeviceCommand in it, is that correct?)