views:

111

answers:

1

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.

+1  A: 

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.

Reed Copsey
is it "lightweight" enough for me? I will have lots of them since I want to implement every code line as separate control
codymanix
I'd recommend a singe FlowDocument for your whole file, and allow it to "flow" through multiple lines, replacing sections with controls as needed. If you're doing each line as a separate control, then you'll probably want to use a WrapPanel, with inter-mixed TextBlock and TextBox elements. See: http://msdn.microsoft.com/en-us/library/ms754037.aspx
Reed Copsey