0

スケジュール名、日時が表示されているリストがありますが、リストボックス内の特定のアイテムを長押しすると、特定のアイテムの説明とスケジュール名のみが表示されるコンテキストメニューが開きます。 。

したがって、xamlのコードは次のとおりです。最初にグリッドにリストボックスがあり、listbox.itemtemplateにscheduleList ansdであるリスト全体がバインドされ、データテンプレート内に特定のアイテムがテキストブロックにバインドされています。

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <ListBox x:Name="scheduleListbox" ItemsSource="{Binding scheduleList}" Hold="scheduleListbox_Hold" Tap="scheduleListbox_Tap" >
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Vertical" Height="150" Width="460">
                    <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" Hold="StackPanel_Hold">
                        <TextBlock x:Name="textBlock3" Text="{Binding StartTime}" Margin="0,5,0,0"/>
                        <TextBlock x:Name="textBlock4" Text="{Binding EndTime}" Margin="50,5,0,0"/>
                        <toolkit:ContextMenuService.ContextMenu>
                            <toolkit:ContextMenu x:Name="menuItem" VerticalOffset="100.0" IsZoomEnabled="True" >

                                <toolkit:MenuItem Header="Add to calender" ItemsSource="{Binding ScheduleName }"/>
                                <!--<toolkit:MenuItem Header="Description"  ItemsSource="{Binding Description}"/>-->

                            </toolkit:ContextMenu>
                        </toolkit:ContextMenuService.ContextMenu>
                    </StackPanel>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

コードまたはxamlのいずれかによって、コンテキストメニューで説明とスケジュール名をバインドする方法を教えてください。

コードまたはxamlを介してコンテキストメニューのデータをバインドするにはどうすればよいですか?

4

1 に答える 1

1

以下のコードを使用して、バインディングを使用してブレッドクラムのコンテキストメニューを作成します。関心のあるコードは、バインディングを指定するtoolkit:ContextMenu.ItemTemplateセクションです。インデックス値の場合と同じように、コマンドパラメータにバインドすることもできます。

toolkit:ContextMenu.Templateセクションは必要ありません。これを追加して、画面に収まる以上のアイテムがある場合にアイテムをスクロールできるようにし、メニューを画面の下部に移動できるようにしました。

    <toolkit:ContextMenuService.ContextMenu>
        <toolkit:ContextMenu x:Name="breadCrumbContextMenu" ItemsSource="{Binding CloudViewModel.BreadCrumbMenuItems}" Opened="ContextMenu_Opened" Closed="Breadcrumb_ContextMenu_Closed">
            <toolkit:ContextMenu.Template>
                <ControlTemplate TargetType="toolkit:ContextMenu">
                    <Border Margin="0,700,0,0" BorderThickness="1" >
                        <ScrollViewer MaxHeight="700">
                            <ItemsPresenter/>
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </toolkit:ContextMenu.Template>
            <toolkit:ContextMenu.ItemTemplate>
                <DataTemplate>
                    <toolkit:MenuItem Click="breadcrumbMenuItem_Click" CommandParameter="{Binding Index}" Padding="0">
                        <toolkit:MenuItem.Header>
                            <StackPanel Orientation="Horizontal" Height="40">
                                <Image Source="{Binding Image}" Width="40" Height="40" />
                                <TextBlock Text="{Binding Text}" Margin="24,0,0,0" />
                            </StackPanel>
                        </toolkit:MenuItem.Header>
                    </toolkit:MenuItem>
                </DataTemplate>
            </toolkit:ContextMenu.ItemTemplate>
        </toolkit:ContextMenu>
    </toolkit:ContextMenuService.ContextMenu>
于 2013-03-06T07:57:05.510 に答える