RichTextBox FormatBar in code behind

二次信任 提交于 2019-12-11 12:29:55

问题


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


回答1:


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);


来源:https://stackoverflow.com/questions/4610742/richtextbox-formatbar-in-code-behind

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!