this.Control不起作用
|
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
namespace WpfTestApp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
string myName;
myName = \"textBox1\";
this.Controls.Find(myName);
}
}
}
上面的代码返回以下错误:
错误1 \'WpfTestApp.MainWindow \'不包含\'Controls \'的定义,并且找不到扩展方法\'Controls \'接受类型为'WpfTestApp.MainWindow \'的第一个参数(是否缺少使用指令还是程序集引用?)
tell1ѭ不提供Controls
作为智能感知的选项。但是我之前在代码示例中看到过3。但是我似乎无法正常工作。
任何帮助将不胜感激,我在Visual Studio 2010中使用c#
没有找到相关结果
已邀请:
3 个回复
场竟矩喘崩
这是
方法,将找到与
相关联的东西。
舜辉
是WinForms属性,但是您正在使用WPF。 WPF完全不同。例如,
类不支持子级,这就是为什么没有
属性的原因。 不知道您要实现什么目标,很难推荐正确的解决方案。
师埠女
如果您为控件分配了
,它将起作用。 请查看此答案,因为这是更可靠的解决方案。