School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,149 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,867 people online right now. Registration is fast and FREE... Join Now!



Invoke WPF RichTextBox equivilant to Win.Forms?

Invoke WPF RichTextBox equivilant to Win.Forms? Wondering what the equivilance of invoking a RTB in winforms vs WPF Rate Topic: -----

#1 coden4fun  Icon User is offline

  • if(coden4fun.NotTired){ ContinueToCode(); }
  • Icon
  • View blog
  • Group: Author w/DIC++
  • Posts: 514
  • Joined: 27-February 09


Dream Kudos: 425

Post icon  Posted 28 February 2009 - 07: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 - 10:50 PM

Was This Post Helpful? 0
  • +
  • -


#2 PsychoCoder  Icon User is offline

  • apt-get install DIC.bin
  • Icon
  • View blog
  • Group: Admins
  • Posts: 16,214
  • Joined: 26-July 07


Dream Kudos: 12400

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Posted 28 February 2009 - 11:24 PM

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

#3 coden4fun  Icon User is offline

  • if(coden4fun.NotTired){ ContinueToCode(); }
  • Icon
  • View blog
  • Group: Author w/DIC++
  • Posts: 514
  • Joined: 27-February 09


Dream Kudos: 425

Posted 28 February 2009 - 11:42 PM

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

#4 PsychoCoder  Icon User is offline

  • apt-get install DIC.bin
  • Icon
  • View blog
  • Group: Admins
  • Posts: 16,214
  • Joined: 26-July 07


Dream Kudos: 12400

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Posted 28 February 2009 - 11:43 PM

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



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month