Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Access a control from another class
3 replies. Latest Post by Mog Liang - MSFT on November 5, 2009.
(0)
imukai
Member
0 points
2 Posts
11-03-2009 9:21 AM |
This might be a newbie question - apologize if it is.
I have a page (MainPage) that's inside my namespace (TestNS).
I have a control on that page - a textbox (TestText).
Within the MainPage.cs I can access TestText with no issues.
However, if I have another class within the same namespace, I cannot access TestText. For that matter, I cannot access any public properties that I create in MainPage. Intellisense ignores them. I've tried MainPage.TestText, I've even tried TestNS.MainPage.TestText and it simply cannot find it.
What am I missing?
Helnix
29 points
3 Posts
11-03-2009 10:30 AM |
for example the project will start at the main class and you do have a textbox on the main class
on class2 create a function accepting a textbox control
class2 myclass2 = new class2()
mainclasstextbox = myclass2.sendcontrol(mainclasstextbox)
you pass mainclass textbox control to other class
//Class2 function
public textbox sendcontrol(textbox mainclasstextbox)
{
//you do somthing with the mainclasstextbox
return mainclasstextbox;
}
something like that.
Thanks
11-03-2009 10:43 AM |
I really don't want to go this route, since it forces MainPage to be aware of Class2. I want Class2 to be able to alter the public properties of MainPage without MainPage having to do anything special for Class2.
Is there something in Silverlight's UserControl that prevents this from working? MainPage is, in fact, a UserControl.
Mog Lian...
All-Star
15884 points
1,541 Posts
11-05-2009 12:23 AM |
Hi,
TestText is not static field, you need access it from MainPage instance. for example:
MainPage myInstance = new MainPage();
myInstance.TestText.Text="Hello";
Thanks,