【问题标题】:scanning buttons from grid WPF in c#从 C# 中的网格 WPF 扫描按钮
【发布时间】:2015-04-09 09:50:54
【问题描述】:

我有一个 WPF 项目。我想创建一种方法来扫描属于我的网格的所有按钮。你知不知道怎么?类似的东西

foreach (PropertyInfo item in t.GetType().GetProperties())

仅适用于 WPF 中的网格。

【问题讨论】:

    标签: c# wpf button foreach


    【解决方案1】:

    这应该可以完成工作。

    public List<Button> GetButtonsFromGrid (Grid grid)
    {
        return grid.Children.OfType<Button>().ToList<Button>();
    }
    

    【讨论】:

      【解决方案2】:

      根据您提供的非常有限的信息:

      foreach (Button b in grid1.Children)
      {
          MessageBox.Show(b.Name);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-06-08
        • 1970-01-01
        • 1970-01-01
        • 2021-12-30
        • 2021-05-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多