0

这适用于 Windows Phone 7.5

我无法根据枢轴项从我的上下文菜单中删除菜单项。我有三个枢轴项,我需要在上下文菜单中显示自定义项。

我正在尝试找到可以帮助我捕获当前数据透视项的正确事件,并基于此我想呈现上下文菜单选项。

更新#1:

Xaml 标记:

 <controls:PivotItem x:Name="HighPivotItem" Header="high">
        <toolkit:ContextMenuService.ContextMenu>
            <toolkit:ContextMenu Opened="ContextMenu_Opened" 
                           Closed="ContextMenu_Closed">
                <toolkit:MenuItem Header="mark as done" Click="MarkMenuItem_Click"/>
                <toolkit:MenuItem Header="edit" Click="EditMenuItem_Click"/>
                <toolkit:MenuItem Header="delete" Click="DeleteMenuItem_Click"/>
            </toolkit:ContextMenu>
        </toolkit:ContextMenuService.ContextMenu>
        <Grid>
            <TextBlock x:Name="HighTextBlock" Text=""
      Visibility="Collapsed" Margin="22,17,0,0"
 Style="{StaticResource PhoneTextGroupHeaderStyle}" />

            <ListBox x:Name="HighListBox" 
             ItemTemplate="{StaticResource DataTemplate}"
             SelectionChanged="ListBox_SelectionChanged" />
        </Grid>
    </controls:PivotItem>

这是我的活动中的代码:

void MarkMenuItem_Click(object sender, RoutedEventArgs e)
{
  Task task = (sender as MenuItem).DataContext as Task;

  // Move from the task list to the done list
  Settings.TaskList.Value.Remove(task);
  Settings.DoneList.Value.Add(task);

  RefreshLists();
}
4

1 回答 1

1

您应该为每个数据透视项目设计上下文菜单

        <controls:Pivot Title="Pivot">
            <controls:PivotItem Header="one" DataContext="{Binding Task}">
                <!-- Stuff for pivot ONE -->
                <toolkit:ContextMenuService.ContextMenu>
                    <toolkit:ContextMenu >
                        <toolkit:MenuItem Header="Menu for both"/>
                        <toolkit:MenuItem Header="Menu for item ONE"/>
                    </toolkit:ContextMenu>
                </toolkit:ContextMenuService.ContextMenu>
            </controls:PivotItem>
            <controls:PivotItem Header="two">
                <!-- Stuff for pivot TWO -->
                <toolkit:ContextMenuService.ContextMenu>
                    <toolkit:ContextMenu >
                        <toolkit:MenuItem Header="Menu for both"/>
                        <toolkit:MenuItem Header="Menu for item TWO"/>
                    </toolkit:ContextMenu>
                </toolkit:ContextMenuService.ContextMenu>
            </controls:PivotItem>
        </controls:Pivot>

菜单可以放置在列表框的数据模板中,也可以放置在单个项目上。

上面的例子假设页面有一个 DataContext 有一个属性“Task”

public MainPage()
{
    this.DataContext = new ViewModel { Task = new Task() };
    InitializeComponent();
}
于 2012-05-18T06:20:06.050 回答