对不起,有一个潜在的愚蠢问题,我对此仍然陌生。我非常感谢你的帮助。 参考Get a Windows Forms control by name in C# 但我没有“this.Controls”可用。有什么我在这里失踪?找不到this.Controls - 我错过了什么?
换句话说,当我输入“this”。和Visual Studio填充选项列表,没有“控件”选项。
对不起,有一个潜在的愚蠢问题,我对此仍然陌生。我非常感谢你的帮助。 参考Get a Windows Forms control by name in C# 但我没有“this.Controls”可用。有什么我在这里失踪?找不到this.Controls - 我错过了什么?
换句话说,当我输入“this”。和Visual Studio填充选项列表,没有“控件”选项。
如果您正在寻找通过无论什么原因,控制迭代,在你的窗口类,你可以通过LayoutRoot的儿童(如)
foreach (object o in this.LayoutRoot.Children)
{
MessageBox.Show(o.GetType().Name);
}
迭代
请记住,孩子们也可以包含孩子,所以你需要根据需要深入研究这些孩子。
你给的链接是Winforms,你正在寻找一种WPF方式来做到这一点,这是不同的。
在WPF中,你应该尝试this.FindName(string name)
Button b = (Button)this.FindName("button1");
代码上下文中的“this”是什么? – 2010-05-20 14:57:59
您链接的问题是针对Winforms,而您正在使用WPF。 – Powerlord 2010-05-20 14:58:24
有些背景会有所帮助。这是什么”? – 2010-05-20 14:58:59