1

Is there a way to access wpf ui elements from a static method? I'm trying to access a textbox string from a static method to no avail

1
  • You can access only static members form your static mehod.. Commented May 30, 2011 at 10:10

2 Answers 2

2

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.)

Sign up to request clarification or add additional context in comments.

2 Comments

Use <blockquote> to display quotes.
That Wiki quote doesn't apply in this case - it is referring to a static method trying to refer to the "instance" of the class it is in.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.