0
 i have a listbox that shows schedule name,date,time and when i long press the particular item of listbox then it opens a context menu in which i have two items that is add to calendar and view description,so i want that wen i click view description then it will open a popup and display the description of the selected item in a list box.

コンテキストメニューの選択したインデックスを取得する方法を教えてください??? xamlの私のコードは次のとおりです。

 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <ListBox x:Name="scheduleListbox" ItemsSource="{Binding scheduleList}" Tap="scheduleListbox_Tap" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                       <StackPanel Orientation="Vertical" Height="150" Width="460">
                            <toolkit:ContextMenuService.ContextMenu>
                                <toolkit:ContextMenu>
                                    <toolkit:MenuItem Header="Add To Calendar"/>
                                    <toolkit:MenuItem Header="View Description" Click="MenuItem_Click"/>
                                </toolkit:ContextMenu>
                            </toolkit:ContextMenuService.ContextMenu>
                            <TextBlock x:Name="textBlock1" Text="{Binding ScheduleName}" Foreground="WhiteSmoke" FontSize="32"/>
                            <TextBlock x:Name="textBlock2" Text="{Binding ScheduleDate}" Foreground="Red" Margin="0,10,0,0"/>
                            <StackPanel Orientation="Horizontal" Height="70" Width="460">
                                <TextBlock x:Name="textBlock3" Text="{Binding StartTime}" Margin="0,5,0,0"/>
                                <TextBlock x:Name="textBlock4" Text="{Binding EndTime}" Margin="50,5,0,0"/>
                            </StackPanel>
                        </StackPanel>

                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </Grid>

特定のアイテムの説明を表示をクリックするとポップアップが開き、その特定のアイテムのスケジュール名と説明が表示されるコンテキストメニューで選択したインデックスを取得する方法を教えてください

4

1 に答える 1

0

コンテキストメニュー項目のクリックハンドラーで、これを使用してクリックされた項目を取得できます:(ScheduleItemをリスト項目のクラス名に置き換えます)

ListBoxItem contextMenuListItem = (ListBoxItem)(scheduleListbox.ItemContainerGenerator.ContainerFromItem(((MenuItem)sender).DataContext));
ScheduleItem item = (ScheduleItem)contextMenuListItem.Content;
于 2013-03-06T20:44:18.980 に答える