English 中文(简体)
WP7 - 背景标准
原标题:WP7 - ContextMenu doesn t show on Hyperlink

I m trying to programmatically add a ContextMenu to a Hyperlink. I ve searched in the documentation and in forums, and seems that the correct solution should be this:

var link = new Hyperlink();
link.Inlines.Add(new Run() { Text = linkText });
link.FontWeight = FontWeights.Bold;
link.TargetName = linkText;
link.Click += new RoutedEventHandler(link_Click);

ContextMenu menu = new ContextMenu();
MenuItem item = new MenuItem();
item.Click += new RoutedEventHandler(CopyLink);
item.Header = "copy link";
item.Tag = linkText;
menu.Items.Add(item);
ContextMenuService.SetContextMenu(link, menu);

该法典编纂了,没有提出任何例外。 在超链接中确实添加了I ve 测试和SentMenu。 问题是,它不会有任何时间。 我可以主宰和安放;把世界所有时间联系起来,菜单不会出现。 此外,还试图与Gesture Service和GestureListener一道增加一名听众,但霍尔德事件根本不会发生火灾。

谁能帮助我? 感谢。

最佳回答

我在阅读Windows Telephone 7.5 Unleashed书时刚刚找到答案。 我的问题是,我需要在RichTextBox增加超级链接,我只能使用Inlines显示案文。 超级链接是一种内线,但并不支持背景信息。 正如Tim所建议的,我需要使用超链接Button。 解决办法是,有一个称为“。 因此,

var inline = new InlineUIContainer { Child = SomeHyperlinkButton }

让我trick。

问题回答

You can t do ContextMenus on Hyperlinks. You can do it on a HyperlinkButton, though. I m not exactly sure of the reason, but it does work. Depending on what you re trying to do, HyperlinkButton may have been what you wanted anyway (Hyperlink is usually only used inside documents of text).





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签