I have a list view, which items are defined using ItemsSource
.
The ItemsSource
is a list of local class type.
I need to send as a CommandParameter
the selected items DataType
.
Can someone help me with this?
Code: (This code is in the App.xaml and the data template is inside an itemsTemplate tag)
<Application.Resources>
<DataTemplate x:Key="xxx" DataType="BL:DeviceInfo">
<StackPanel>
<Button Command="{Binding DataContext.SelectDeviceCommand RelativeSource={RelativeSource ancestorType=ListView}} CommandParameter="{???????}" />
</StackPanel>
</DataTemplate>
</Application.Resources>
I wand to send the SelectedItem as a Deviceinfo , which is the type of the items of the list that is the items source of the list view.
Easiest is:
This will send the DataContext object itself as a command parameter. Then you can derive it's type in the handler for the command.
If you NEED the type itself to the sent as a parameter you'll need to create a converter.
http://msdn.microsoft.com/en-us/library/system.windows.data.binding.converter(v=vs.110).aspx