Passing Item (entire class) of Parent Control List to Command

时间:2016-02-12 21:35:40

标签: wpf mvvm

Is there a way to pass a child entire class of parent Collection Control (in my case ListBox) into Command in ViewModel? I can pass any single value, either 'IsChecked', 'AttachmentId', or 'Name'. All three properties are part of 'Attachment' class. 'AttachmentLst' (item source of ListBox contains 'Attachment' elements. I would like to pass entire class into my Command. Below is working code for passing just one property, in this case 'AttachmentId'. How to pass 'Attachment' into the Command?

df.set_index('Name').T.plot(kind='bar', stacked=True)

ViewModel

            <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>

1 个答案:

答案 0 :(得分:0)

use

<p><a class="btn btn-lg btn-danger btn-block" href="{% url 'social:begin' 'google-oauth2' %}">Entrar con la cuenta de Google</a></p>

to pass entire item as CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type StackPanel}},Path=DataContext}" .

You can also use CommandParameter/ templateParent Binding instead of Self Binding. DataContext will be the same for all.