在 c# 中从网格 WPF 扫描按钮

scanning buttons from grid WPF in c#

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

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

仅适用于 WPF 中的网格。

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

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

这应该可以完成工作。

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