事件处理程序不使用动态生成的xaml按钮

时间:2018-01-10 11:59:42

标签: c# xaml

private void createCarers()
    {
        foreach (Carer c in CarerManager.Carers.Values)
        {
            Button x = new Button
            {
                Content = c.name,
                MinHeight = 50,
                Tag = c,
                Margin = new Thickness(0, 0, 0, 10)
            };
            x.Click += new RoutedEventHandler(carerClick);
            carersPanel.Children.Add(x);
        }
    }

    private void carerClick(object sender, RoutedEventArgs e)
    {
        System.Windows.Application.Current.Shutdown();
    }

好的,所以在窗口初始化时会调用createCarers

为什么这不起作用?关机事情只是一个测试,但它不起作用。

0 个答案:

没有答案