Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access one window's control (richtextbox) from another window in wpf?

I'm sure this is something very simple but I can't figure it out. I've searched here and on msdn and have been unable to find the answer. I need to be able to set the richtextboxes selection via richtextbox.Selection.Select(TextPointer1, Textpointer2).

like image 459
Justin Avatar asked Feb 08 '10 01:02

Justin


1 Answers

Application.Current contains a collection of all windows in you application, you can get the other window with a query such as

var window2 = Application.Current.Windows
    .Cast<Window>()
    .FirstOrDefault(window => window is Window2) as Window2;

and then you can reference the control from your code, as in

var richText = window2.MyRichTextBox
like image 82
Ian Oakes Avatar answered Sep 28 '22 16:09

Ian Oakes