Is it just me or do none of the richTextBox controls work properly(WPF)?
Posted in: enart.nnmj.com Date: March 14th, 2010

I want to be able to open a window with a rich text box in it, click the bold button and begin typing in bold. Yet the only documentation regarding the RTB controls in WPF is how to make selected text bold. You cant throw a rock without hitting a blog or forum that explains or discusses this. Yet I cant find anywhere the C# that applies bold to all of the text. Don’t some people actually prefer to first setup the font, wieght, style, etc before they start typing?
Aftter I read about RTB controls here and downloaded the kWordpad to test out, I actually had to open wordpad myself, click the bold button and start typing (just to see if I was losing my marbles). This is how the native word processors work, but none of the WPF apps containing a rich textbox that I have tested in the past week or so have this feature, but nobody seems to be bothered by this fact.
So what am I missing?
So I went into the source and added: "this.MainRichTextBox.Focus();" directly benieth “InitializeComponent” to the Window1.xaml.cs file, so that the rich textbox would already have been ‘clicked’ upon opening and now it works just like wordpad as far as applying styles.
Are you getting similar behavior or not? If its working differently for you, is there any chance you know whats happening here?
Either way, thanks for making me take a second look. And just while I have you on the line, I want to tell you I love the website. The tutorials here are great. Most sites simply give snippits, but don’t give you all of how they achieved this or that feature. So its nice to know that when I start something here, all of the info I need to finish it or get it working is included. I'm looking forward to more in the WPF field.
Thanks again.
P.S. Just as a side note I was curious why you have:
private void SelectDefaultFont()
{
FontFamilyCombo.SelectedValue = "Arial";
}
in the Window1.xaml.cs file when the Selected Index is already set in Expression Blend (0).
Just for fun I changed it to: SelectedValue=”Calibri” in the C# file and left the Selected index in Expression Blend at 0. Now when I run kWordpad the combo box has Calibri set as the defualt but resets to Arial as soon as I begin typing in the rich textbox.
What makes this really odd to me is that if it is being set by the selected index in Expression Blend, then the selected index would have to be set at 9 on my computer in order for it to choose Arial as the default (for me 0 is Abyssinica SIL). So where is it getting Arial from; and how is it that it is ignoring both the SelectedDefaultFont and the SelectedIndex? I realize this may seem tedius, but I just hate not knowing... "to be continued" at the end of a tv show makes me nuts too; I'm seeking help.
As for the problem with the font style controls; they still don’t seem to work properly. At this point it feels like I am trying to trick them into working the way we expect them to.
I think the the check preformed at the beginning of the Window1.xaml.cs file is causing some of the strange behavior. For instance if you open the application, click the bold button and then click in the RTB before you begin actually typing, the bold button will uncheck itself in order to reflect the current unbold state of the RTB (since the default state of the RTB is not bold). So maybe rewording that operation will fix the problem.
Any thoughts... anybody?
(This is how it is working after adding the MainRichTextBox.Focus to the cs file.)
#If you have any other info about this subject , Please add it free.# |
