适用于Windows Phone 7.5
我无法根据pivotitem从我的上下文菜单中删除菜单项。我有三个pivotitems,我需要在上下文菜单中显示自定义项。
我正在尝试找到能够帮助我捕获当前枢轴项目的正确事件,并基于此我想要显示上下文菜单选项。
更新#1:
Xaml Markup:
<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();
}
答案 0 :(得分: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();
}