如何从其他类或窗口访问Windows wpf应用程序中的控件 [英] How Can I access a control in windows wpf application from another class or windows

查看:69
本文介绍了如何从其他类或窗口访问Windows wpf应用程序中的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我想在wpf中的mainWindow中访问我的控件,如按钮或文本框,但我不能这样做。

在Windows窗体应用程序中它很容易,你可以将该控件的修饰符设置为True,你可以从该mainWindow的实例到达该控件,但是在WPF中我不能声明一个公共控件,我怎么做?

Hi everyone

I want to access my controls like button or textbox in mainWindow in wpf, but I cant do this.
in windows form application its so easy, you can set modifier of that control to True and you can reach that control from instance of that mainWindow, but in WPF I can''t declare a pubic control, How ca I do this?

推荐答案

Just declare your control like this to make it public:

<TextBox x:Name="textBox1" x:FieldModifier="public" />

You can then access it from another control.


这篇关于如何从其他类或窗口访问Windows wpf应用程序中的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆