A really simple setup - Visual Studio 2010's default new WPF project, with MainWindow and App classes and XAML. On MainWindow there's only a simple control, a texbox, let's call it TB. All I'm trying to do is access, read and modify TB's properties from another class, such as App. That's all the code I have written,开发者_Python百科 still, no can do. I prefer not to assign the values from TB's properties to variables, but manage them directly.
The class in which you want to modify the TB, store the TB's reference in that class. Then using that reference you can modify the properties of TB.
do something like this..
public class MyClass
{
Textbox m_TextBox;
public MyClass(Textbox TB)
{
m_TextBox = TB;
}
ModifyTextbox()
{
m_TextBox.Text = "Hello World";
}
}
in the MainWindow.cs create a new instance of MyClass
MyClass myClass = new MyClass(TB);
精彩评论