将单击事件添加到HyperLink按钮的Windows 8应用程序不起作用

时间:2014-08-08 07:37:42

标签: c# windows windows-8 windows-8.1

我有一些超链接按钮,我已经以编程方式添加了单击侦听器。但是不会调用在事件处理程序中编写的代码。我错过了什么吗?以下是代码

    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!!!!
    }

1 个答案:

答案 0 :(得分:3)

删除

button.IsHitTestVisible = false;

或将其设为true