School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,308 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,078 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

coden4fun

28 Feb, 2009 - 07:50 PM
Post #1

D.I.C Regular
Group Icon

Joined: 27 Feb, 2009
Posts: 288



Thanked: 6 times
Dream Kudos: 350
My Contributions
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.

CODE


//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

CODE

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 Feb, 2009 - 10:50 PM

User is offlineProfile CardPM
+Quote Post


PsychoCoder

RE: Invoke WPF RichTextBox Equivilant To Win.Forms?

28 Feb, 2009 - 11:24 PM
Post #2

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,701



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Have a look at the Dispatcher Object
User is offlineProfile CardPM
+Quote Post

coden4fun

RE: Invoke WPF RichTextBox Equivilant To Win.Forms?

28 Feb, 2009 - 11:42 PM
Post #3

D.I.C Regular
Group Icon

Joined: 27 Feb, 2009
Posts: 288



Thanked: 6 times
Dream Kudos: 350
My Contributions
Thank you that helps me out significantly.
User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: Invoke WPF RichTextBox Equivilant To Win.Forms?

28 Feb, 2009 - 11:43 PM
Post #4

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,701



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
No problem, glad I could help smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 01:49PM

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