开发者

Access TextBox String from static method

Is there a way to access wpf ui eleme开发者_如何学编程nts from a static method? I'm trying to access a textbox string from a static method to no avail


This would be impossible. Your static method can run while the textbox doesn't exist because there is no instance of your form.
Static methods are designed to be able to run without any instance.
Quote from wikipedia:

Therefore, a static method cannot refer to a specific instance of the class (i.e. it cannot refer to this, self, Me, etc.)


Need more code to give a better answer.

e.g. if you pass in a Window parameter to the static method or if you pass in the ViewModel object that has the property to which your textbox binds to, I'd say you would be able to affect the WPF UI from your static method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜