anyone that can help me with this?

Hello,

I'm experiencing the following problem for a while now. I'm not able to set the text of a textbox from another class in the same app. Can anyone tell me how I should do this. More details below...

Window1-code:
<Window x:Class="TestWindow.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TestWindow">
<Grid>
<TextBox Name="txtTest"></TextBox>
</Grid>
</Window>

Class1-code:
//Following is a method that is called from elsewhere
public void SendRtlsEvent(string code, double x, double y, DateTime timeStamp) {
// Here I want to display the string below into the txtTest of Window1
// ("ping received for {0} at location ({1},{2}) at {3}", code, x, y, timeStamp);
//
// When using a log file, everything goes smoothly.
// _log.InfoFormat("ping received for {0} at location ({1},{2}) at {3}", code, x, y, // timeStamp);
// So there is no problem with the traffic of the data.
//
// Can someone just show me how to put static text into the the txtTest from here
// Thanks in advance
}


Answer this question

anyone that can help me with this?

  • K.Paing

    Could you suggest anything that would be good design

    I tried what you said, but Application.Windows doesn't exist. Although I have multiple windows. When I use Application.Window1, I can't even acces public methods of that window.



  • Shay Van Creveld

    i've been delaying on starting up a blog, so i decided to just do it today. i wrote a little article on how you might use databinding in this scenario. it might not be completely applicable in this particular case, but it might help others who are looking at similar problems. hope it helps!

    http://eric.burke.name/dotnetmania/2006/04/13/12.48.08


  • Cordelia

    I guess not, since the intellisence doesn't give me the opportunity to use Application.Current.

  • strazz

    Sorry, it's Application.Current.MainWindow and Application.Current.Windows. Anyway, I have read from the documentation that these properties are not accessible from outside the UI thread. So the question is SendRtlsEvent method executes in the UI thread or not


  • HKSunny

    Application class is defined in System.Windows namespace so you'll have to import it.


  • Gette

    Althougn, in my opinion, it's not good design, you can use the Application.MainWindow property (if you have only one window) or the Application.Windows array, do a cast to your window class (TestWindow.Window1) and set the txtTest. Of course, txtTest is private so you'll have to declare a public method in the window to set it. And if the method SendRtlsEvent is not in the UI thread you must use the dispatcher.


  • joe moe

    Kimme,

    Is this the same issue you posted about earlier

    Cheers

    Simon



  • 0010110

    the issue to set the content of a control from another class Yes, it sure is

  • anyone that can help me with this?