tinmac
tinmac

Reputation: 2580

RichTextBox FormatBar in code behind

Im looking at the codeplex WPF extended RTB and id like to perform the following in code behind:

<RichTextBox>
   <toolkit:RichTextBoxFormatBarManager.FormatBar>
       <toolkit:RichTextBoxFormatBar />
   </toolkit:RichTextBoxFormatBarManager.FormatBar>
</RichTextBox>

Im having brain drain, I have the following in my code behind but cant wire it up!

        Microsoft.Windows.Controls.RichTextBox rtb_wording = new Microsoft.Windows.Controls.RichTextBox();// USE extended RTB
        Microsoft.Windows.Controls.RichTextBoxFormatBarManager manager = new RichTextBoxFormatBarManager();
        Microsoft.Windows.Controls.RichTextBoxFormatBar formatBar = new Microsoft.Windows.Controls.RichTextBoxFormatBar();

Any help really appreciated

Upvotes: 1

Views: 1148

Answers (1)

user1234567
user1234567

Reputation: 613

You shouldn't create an object of type RichTextBoxFormatBarManager. Instead, use a static method of this class like I wrote below. Note that "myCanvas" is the name of the grid/canvas container. Change it to whatever name you have for your container.

        Microsoft.Windows.Controls.RichTextBox rtb_wording = new Microsoft.Windows.Controls.RichTextBox();        
        Microsoft.Windows.Controls.RichTextBoxFormatBar formatBar = new Microsoft.Windows.Controls.RichTextBoxFormatBar();
        Microsoft.Windows.Controls.RichTextBoxFormatBarManager.SetFormatBar(rtb_wording,formatBar);

        rtb_wording.Width = 400;
        rtb_wording.Height = 200;

        myCanvas.Children.Add(rtb_wording);

Upvotes: 2

Related Questions