OnClick on generated Textblock
Howdy, I'm开发者_如何学C generating a bunch of Textblocks in a StackPanel. I would love to open another page when clicking on one Textbox:
sp.Children.Add(new TextBlock { Text = "Click me, I wanna open new content" });
How could I do that, it's probably something with "triggers" but I couldn't find anything on the web :-/.
Thanks!
You could use the Toolkit to add a gesture listener for the Tap
event.
Alternatively you could use a HyperlinkButton as this contains a Click
event.
Edit:
Example of using HyperlinkButton:
var sp = new StackPanel();
var hlb = new HyperlinkButton {Content = "click me"};
hlb.Click += hlb_Click;
sp.Children.Add(hlb);
ContentPanel.Children.Add(sp);
private void hlb_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/AnotherPage.xaml", UriKind.Relative));
}
Use TextBlock.ManipulationStarted
event to detect a touch on it.
精彩评论