我有一些超链接按钮,我已经以编程方式添加了单击侦听器。但是不会调用在事件处理程序中编写的代码。我错过了什么吗?以下是代码
private void createTextBlocksForEachLavel(List<Folder> parents)
{
foreach(Folder parent in parents){
addHyperLinkButton(parent.Name);
}
}
private void addHyperLinkButton(String name)
{
HyperlinkButton button = new HyperlinkButton();
button.IsHitTestVisible = false;
button.VerticalAlignment = VerticalAlignment.Bottom;
button.Foreground = new SolidColorBrush(Colors.Black);
button.FontFamily = new FontFamily("Segoe UI Light");
button.FontSize = 20;
button.Content = name;
if (!name.Equals(">"))
{
button.Click += button_Click;
}
hierarchy.Children.Add(button);
}
void button_Click(object sender, RoutedEventArgs e)
{
// some code which does not get executed!!!!
}
答案 0 :(得分:3)
删除
button.IsHitTestVisible = false;
或将其设为true