ListBoxItem, ContextMenu.

Topics: Actions & Coroutines, Conventions, UI Architecture
Aug 29, 2011 at 9:13 AM
Edited Aug 31, 2011 at 1:13 AM

I am trying to get a context menu to show and then be able to select the Edit/Delete entries available on the listbox. I have an ActionMessage wtih a Parameter with value of $dataContext, I am assuming that it should pass thru the "Schedule" object for processing, I am guessing the method signature is not correct therefore it fails. Not sure what is going unless the $dataContext isn't what I think it is. In that case how would I debug this to see what exactly is going on?

<ListBox.ItemTemplate>
    <DataTemplate>
        <Grid Margin="12,0,0,0">
            <tk:ContextMenuService.ContextMenu >
                <tk:ContextMenu >
                    <tk:MenuItem Header="Edit">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Click">
                                <cm:ActionMessage MethodName="ScheduleEdit">
				<cm:Parameter Value="$dataContext" />
                                </cm:ActionMessage>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </tk:MenuItem>
                    <tk:MenuItem Header="Delete">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Click">
                                <cm:ActionMessage MethodName="ScheduleDelete">
				<cm:Parameter Value="$dataContext" />
                                </cm:ActionMessage>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </tk:MenuItem>
                </tk:ContextMenu>
            </tk:ContextMenuService.ContextMenu>
            <StackPanel Grid.Column="1" Grid.Row="1" Margin="0,0,0,5">
                <StackPanel Orientation="Horizontal" Margin="0,0,0,-9">
                    <TextBlock Text="PAIRING:" Margin="0,0,-5,0" Style="{StaticResource PhoneTextLargeStyle}" />
                    <TextBlock Text="{Binding Pairing}" Style="{StaticResource PhoneTextLargeStyle}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="0,0,0,0">
                    <TextBlock Text="{Binding Path=Date, Converter={StaticResource StringDateFormatter}, 
ConverterParameter=\{0:MM/dd/yyy HH:mm\}}
" Margin="0,0,12,0" Style="{StaticResource PhoneTextLargeStyle}"/> <TextBlock Text="BLOCK:" Margin="0,0,-5,0" Style="{StaticResource PhoneTextSubtleStyle}" /> <TextBlock Text="{Binding TotalBlock}" Margin="6,0,5,0" /> </StackPanel> </StackPanel> </Grid> </DataTemplate> </ListBox.ItemTemplate>


What am I missing with this?

Aug 31, 2011 at 1:13 AM
Edited Aug 31, 2011 at 1:25 AM

Updated for clarity

context.Target  and context.View are both null if that helps.

Aug 31, 2011 at 6:15 AM

I solved this by moving the contextmenu service outside of the data temple into the main part of the ListBox and then used the SelectedItem property to get the values necessary to provide the data for the menu operations.