I have a custom text editor derived from RichTextBox where the user can drag an object into the box and it displays the object's name (amongst other, keyboard entered, text). I would like to treat this name as a single, uneditable, entity: the user can only delete the whole name and can't change anything on the inside.
I would also like the formatting to be completely isolated from the surroundings. Right now I insert it as a separate Run. Iff the user places the cursor at the end of the name, the new keyboard entered text has the name formatting which I don't want.
FYI, for anyone else trying to do something similar, I was able to do this by using an InlineUIContainer holding a TextBlock.
Related
I am using C# WPF with Avalon Edit Text Box.
I am trying to make all of the text in the text box uppercase and I get an error with additional message 'No undo group should be open at this point'.
I am using the following code:
a.Text = a.Text.ToUpper();
where "a" is the AvalonEdit.TextEditor
Thank you.
Setting the TextEditor.Text property has the side-effect of clearing the undo stack (just as with the normal WPF TextBox). Clearing the undo stack is only allowed when there's no open undo group.
If you did not intend to clear the undo stack, use the methods on textEditor.Document instead to modify the document. You'll want to avoid replacing the whole text, because that would also reset the selection and caret position (after all, AvalonEdit can't know how your new text is related to the old text).
If you do want to clear the undo stack (e.g. you're switching the view to a different document), you'll have to figure out why an undo group is open. Most likely, your code is running from the event handler of an event that is called while the undo group is still open (e.g. document.TextChanged) -- you might want to switch to a different event instead (e.g. document.UpdateFinished is called after the undo group was closed).
If all you want to do is to upper-case text as it is being input, it's better to modify the text before it is added to the document: handle the TextArea.TextEntering event to cancel any lower-case input (set e.Handled = true;), and instead call TextArea.PerformTextInput() to repeat the text input process with the corresponding upper-case text instead.
For copy-paste, you could handle the attached DataObject.PastingEvent and modify the data to be pasted.
What I want to do is intercept assignments to the Text property on my control inherited from a TextBox. I the want to modify this text and have the modified text shown in the text box. I aslo need the ability to return something different from what is shown in the text box when the property is read. In Win Forms I could do this by overriding the Text property as it was declared virtual. Obviously things are a bit different with dependency properties. One idea I had was to use OverridePropertyMetadata to have my own callback detect the property change and then call the original callback obtained with GetMetadata. This doesn’t work as property changed callbacks are merged. I’d be interested if there is another way to do it which is specific to this property but I like to find out if it is possible “override” dependency properties in general.
My application is a formatted text box when the text is set to 1000 say (for a numeric format), the text box shows 1,000 but when you read the text you get back 1000 again- the box will keep track of the un formatted text internally. I managed to implement in Win Forms fairly easily but am now trying to port it to WPF.
I think OverridePropertyMetadata is the way to go, but rather than defining a new PropertyChangedCallback, you could write a new CorceValueCallback:
static object CoerceText(DependencyObject d, object baseValue)
{
string s = (string)baseValue;
// Change s to whatever you want
...
return s;
}
Please refer this control
http://www.charlespetzold.com/blog/2009/10/Using-Text-Outlines-in-Silverlight.html
The formattedtext control is a shape which helps to generate the shape of the text with proper geometry. I would like to make this control act like a text box with cursors and features like typing in from keyboard.
Right now I use an invisible text box with a formattedtext control to act like that. But the cursor position always creates a problem when the size of the text is not equal to the size of the rendered text as shape.
Can anyone please show the way to achieve this.
Well, I built a syntax highlighting textbox using the method you describes.
Actually, at first I wanted to rebuilt everything too, but I thought : I have to build the caret fonctionnalities, the selection brush, manage a lot of different events, like selection with mouse or keyboard, deletion, Copy/Cut/Paste, etc etc...
That's a LOT of work, and windows users are used to select text in textboxes for instance, so this complex implementation cannot be left unimplemented. We must follow some Microsoft guidance on how a textbox must feel.
Actually, I think that building a new textbox from scratch is not the way to go. I suggest you to continue on your current method. If you have different fonts in the same textbox, use a RichTextBox, and handle the font changes in the textbox as well as in the formatted text.
Also, a good think to implement is to only draw the visible text with the formattedtext (but only if the user can write several hundreds of text lines).
The idea is rather simple. Some datawindow (not web datawindow) varchar fields contain detailed descriptions. I was wondering if it is possible to provide the following (wikipedia-like) functionality to users: The ability to click (or dbl-click or whatever) on specific words of the text, while reading (which somehow should be indicated as clickable - it would be perfect if they could be colored blue but I don't think this is possible) and open a relevant window (or response). Do you think something like this could be implemented?
To achieve the colour, you could use a rich text edit style if you're using PB 11.5.
For the hyperlink functionality, I'd try to leverage the Clicked event, trying to identify with SelectedStart() what word has been clicked and then whether or not it is a hyperlink. The column would need to have TabOrder so that a click would place the cursor in the text.
Good luck,
Terry.
if you use a RTF datawindow you can insert hyperlinks (in whatever colour or style you wish)
Is is possible to embedd a TextBox in another TextBox. It does not have to be a TextBox, any editable text-component will suffice. I tried it with TextBox and got compiler errors.
Reasoning:
I want to create some kind of source code editor. I want that string literals in my source code are allowed to contain all kinds of special characters like ",'\ and so on. To achieve this, all string literals should be encapsulated in separate textboxes within the source code to separate them from the other text.
Saving and loading of the source is done using xml with all special chars converted to entities, so my only problem is the proper editing. I do not want to put the user off with escaping sequences and so on.
One option for this would be to use a FlowDocument instead of a TextBox. This would let you embed as many TextBlock elements with TextBox controls, and have it "flow" naturally in a document.