将TextBlock HyperLink数据作为HyperlinkClickEventArgs传递给HyperLink.Click处理程序

时间:2016-06-09 19:53:02

标签: c# windows-runtime uwp

我认为这很简单,但无法弄清楚如何传递将在Click处理程序中检索的数据值。 (注意:如果你想试验它,你需要使用Windows.UI.Xaml.Documents 指令。)

Hyperlink hyperlink = new Hyperlink();

// Set various propertis such as hyperlink.Foreground, hyperlink.UnderlineStyle

// add the hyperlink text
hyperlink.Inlines.Add(new Run() { Text = "click me!" });

// subscribe to handler shown below, but I want to pass on a string parameter that
// shows up as (HyperlinkClickEventArgs) e.OriginalSource or even as e.ToString()
// in the Click handler

hyperlink.Click += Hyperlink_Click;  // STUCK HERE in attempting to pass string data


// The hyperlink click event handler -- the sender object is as expected as commented.

private static void Hyperlink_Click(Hyperlink s, HyperlinkClickEventArgs e)
{
    string clickMeString = (s?.Inlines[0] as Run)?.Text; // no problem here!

    // ... BUT I want my parameter as e.OriginalSource to get to more data, but how?
}

0 个答案:

没有答案