I generated a lot of text blocks programmatically. I would like to attach the onclick function to them ... it's easy if I write a text block in my xaml code, but how can I do this if text blocks are programmatically generated?
What I have:
TextBlock tb1 = new TextBlock();
tb1.KeyDown += new System.Windows.Input.KeyEventHandler(MyTextBlock_KeyDown);
...
private void MyTextBlock_KeyDown(object sender, GestureEventArgs e) {
MessageBox.Show("hello world");
}
source
share