Sending data type as command parameter

919 Views Asked by At

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.

1

There are 1 best solutions below

0
On

Easiest is:

CommandParameter="{Binding}"

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