尽管找了一段时间,我还是很难找到好的文档。
我希望在我的应用程序中有一个上下文菜单,可以复制其他点击按住上下文菜单的行为,比如将应用程序固定在应用程序列表的开始屏幕上。
这是我的上下文菜单:
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu x:Name="sectionContextMenu">
<toolkit:MenuItem Header="Hide this section from this list" />
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>我如何让它显示出来呢?
发布于 2010-12-20 00:36:19
上下文菜单需要附加到您希望用户点击并按住的元素。
<Border Margin="0,12" BorderBrush="{StaticResource PhoneForegroundBrush}" BorderThickness="2" Background="Transparent" VerticalAlignment="Center" Padding="16">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu x:Name="sectionContextMenu">
<toolkit:MenuItem Header="Hide this section from this list" />
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<TextBlock Text="Tap and hold here to invoke a ContextMenu" Style="{StaticResource PhoneTextNormalStyle}"/>
</Border>用户现在可以通过轻触并按住此Border元素的内容来调用上下文菜单。
发布于 2012-10-30 21:50:32
根据内容为不同项目提供独特的上下文菜单。
private ContextMenu CreateContextMenu(ListBoxItem lbi)
{
ContextMenu contextMenu = new ContextMenu();
ContextMenuService.SetContextMenu(lbi, contextMenu);
contextMenu.Padding = new Thickness(0);
string item_1 = "item 1";
if(lbi.Content is string) {
item_1 = lbi.Content as string;
}
contextMenu.ItemsSource = new List<string> { item_1, "item 2", "item 3" };
contextMenu.IsOpen = true;
return contextMenu;
}
private void Results_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (Results.SelectedIndex == -1) return;
int index = Results.SelectedIndex;
ListBoxItem lbi = Results.ItemContainerGenerator.ContainerFromIndex(index) as ListBoxItem;
CreateContextMenu(lbi);
Results.SelectedIndex = -1;
}https://stackoverflow.com/questions/4483775
复制相似问题