Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在c中从网格WPF扫描按钮#_C#_Wpf_Button_Foreach - Fatal编程技术网

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

C# 在c中从网格WPF扫描按钮#,c#,wpf,button,foreach,C#,Wpf,Button,Foreach,我有一个WPF项目。我想创建一个方法来扫描网格中的所有按钮。你知道怎么做吗?差不多 foreach (PropertyInfo item in t.GetType().GetProperties()) 仅适用于WPF中的网格。基于您提供的非常有限的信息: foreach (Button b in grid1.Children) { MessageBox.Show(b.Name); } 这应该可以完成任务 public List<Button> GetButtonsFrom

我有一个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>();
}
公共列表GetButtonsFromGrid(网格)
{
返回grid.Children.OfType().ToList();
}

这对我很有帮助,谢谢!