Invoke WPF RichTextBox equivilant to Win.Forms?

Wondering what the equivilance of invoking a RTB in winforms vs WPF

Page 1 of 1

3 Replies - 7793 Views - Last Post: 01 March 2009 - 12:43 AM Rate Topic: -----

#1 coden4fun  Icon User is offline

  • if(coden4fun.NotTired){ ContinueToCode(); }
  • member icon

Reputation: 27
  • View blog
  • Posts: 696
  • Joined: 27-February 09

Invoke WPF RichTextBox equivilant to Win.Forms?

Post icon  Posted 28 February 2009 - 08:50 PM

Hi, I'm wondering what the equivalence of an invoke is when working with any WPF control vs Windows.Forms.

For instance, in a typical windows forms application you could do the following.


//define a Control
private RichTextBox _tempBox;

//Create an accessor for it
private RichTextbox OurRTB
{
	  get { return _tempBox; }
	  set { _tempBox = value; }
}

//then if you needed to use it as an event you would invoke it sort like the following
private void InvokeTempBox()
{
	 _tempBox.Invoke(new EventHandler(delegate
	 {
		   _tempBox.AppenText("appending text \n");
}));
}




However, I have found out, since I have just started the jump from Win Forms to WPF this isn't quite a copy and paste solution. For instance using the same libs that worked in my WinForms, doesn't quite convert nicely in the WPF application.

This is because when you're create the object of a RichTextBox in a windows forms application you're using the class of System.Windows.Forms

but when you're creating the object of a RichTextBox on a WPF application you're using the
class of System.Windows.Controls

and there is no definition for an invoke in this class, so how is someone suppose to create an accessor correctly while working in a WPF application?

The exact error I get when I try to invoke a RichTextBox from the System.Windows.Controls class is the following below

Error	1	'System.Windows.Controls.RichTextBox' 
does not contain a definition for 'Invoke' 
and no extension method 'Invoke' accepting
 a first argument of type 'System.Windows.Controls.RichTextBox' 



And of course if I use a RichTextBox from System.Windows.Forms then I'm going to be getting ambiguous errors for using System.Windows.Controls, which is the class that is used for controls for WPF applications, and I then might as well be going back to a win form...



Thanks for answers in advance

This post has been edited by coden4fun: 28 February 2009 - 11:50 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Invoke WPF RichTextBox equivilant to Win.Forms?

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Invoke WPF RichTextBox equivilant to Win.Forms?

Posted 01 March 2009 - 12:24 AM

Have a look at the Dispatcher Object
Was This Post Helpful? 0
  • +
  • -

#3 coden4fun  Icon User is offline

  • if(coden4fun.NotTired){ ContinueToCode(); }
  • member icon

Reputation: 27
  • View blog
  • Posts: 696
  • Joined: 27-February 09

Re: Invoke WPF RichTextBox equivilant to Win.Forms?

Posted 01 March 2009 - 12:42 AM

Thank you that helps me out significantly.
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Invoke WPF RichTextBox equivilant to Win.Forms?

Posted 01 March 2009 - 12:43 AM

No problem, glad I could help :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1