I am currently working on a Silverlight project and I am using RichTextBox. User are allowed to drag and drop images on to the RTB. I know that the Xaml property a Silverlight RichTextBox doesn't not include any UIElement objects that are present in the content and I need to save the content of this RTB and later load it. Does anyone know of a way to achieve this? Thanks.
You're probably better off traversing the all of the Inlines in the RTB. The InlineUIContainers are Inlines so you can handle those however you'd like.
Your basic strategy should look something like:
Get the Blocks property of the RTB, find all the Paragraphs. Get the Inlines on each Paragraph. For each inline: handle a Run and save as Text. handle InlineUIContainer and save as however you'd like. Handle a Span as a recursive call to find the child Inlines.
If you want to save formatting on the Runs, then you'll have even more code for that.
It's not nearly as easy as using the Xaml property but it's really the only way to handle controls in InlineUIContainers.
Related
I would like to know if there is an easier way to add any kind of visual separation like a line between text lines in a Richtextbox?
If not, is there another component that I can use in a Form that would be able to do this for text lines?
Thank you.
It has been a few years, but at one point I wrote a RichTextBox wrapper that ended up manipulating the underlying markup. It wasn't pretty and it wasn't for the faint of heart, but it did work. I ended up using it to highlight some text I believe.
The key thing you need to know is the specification for the RTF markup language: http://en.wikipedia.org/wiki/Rich_Text_Format should get you started.
The RichTextBox class documentation and the Document property should get you started at modifying the underlying structure of the document after loading or during editing.
I believe am in need of creating custom RichTextBox in C#. One kind of like that:
I admit it might not even have to be RichTextBox, but after some research I decided it's gonna be the easiest way. Functionality I need are icons at each row, checkboxes and text formatting. My program will process each line of the text and mark lines that are correct, incorrect, and strike out lines not necessary in further work, while showing line that's currently processed and allowing user to edit some lines freely (here: lines before Around 3 000 won't be editable, but those under the line will).
What's the problem then? I have no idea how to get it done. I've seen tutorial on how to make single-line textBox with icon or checkbox nearby, but I have no idea how to make both, and for multiline textBox (so I could freely scroll and everything would work fluently). I've read some questions on SO as well, but neither helped me.
I just don't know how to get started, I realize it won't be 5 min work, but I'm willing to do it. Until now I've been only able to create custom control deriving from RichTextBox, but I have no idea which methods and how to override. Any help appreciated.
Try to use WebBrowser control instead RichTextBox.
You can add CheckBoxes and editable content by setting a correct HTML code to it.
Set each TextBox or CheckBoxes ids and use GetElementsByTagName or GetElementById to access inner elements to get or set its attributes or values.
It is possible to export Microsoft Visio drawings as a Website containing Silverlight content. This is described on this blog-post.
The output of such an export are the following:
xaml_1.xaml (contains the structure of the control)
data.xml (contains all text content such as labels, etc)
several java-script files
*.htm pages with a Silverlight container
other files such as *.css and images
I would like to integrate the exported XAML code into another existing Silverlight application. I found this blog-post telling me how to load XAML code dynamically during runtime.
What I would like to know is how to "merge" the XAML-file and the data.xml and how I can get a reference to the items of the XAML code, in order to change certain texts...
In the associated xaml js file (eg xaml_1.js) there's a handleMouseUp function that reads the shape ID from the (XAML) 'name' string and then calls OnShapeClick in frameset.js. This method, which is common to all of the js-based Save as web output types, then calls other methods to populate the details table or retrieve hyperlinks found in data.xml. If you have a look at the FindShapeXML function in frameset.js you'll see that it gets the appropriate data based on the page and shape IDs (note that shape IDs are unique to a page as per Visio itself).
In terms of creating data-bound or dynamic shape text, one workaround for the glyphs issue that #slfan highlights is prevent the text from being output. For example, prior to running Save As Web in Visio, you could loop through all of the shapes and set their HideText ShapeSheet cell to true. This will prevent all of the glyphs xaml being generated and you'll still have access to the text string in data.xml. I guess you wouldn't then benefit from the correct font scaling, but it depends on your scenario. If it was really important to get the scale right then you could parse the RenderTransform attribute (which is described in attribute syntax rather than property element syntax) of the glyph elements.
Glyphs are there (I'm guessing) because it mirrors how Visio works in the application ie in Visio you can select individual characters within a shape's text and apply different fonts and formatting, but if you don't need that, I'd be tempted to ditch the glyphs collection and just use a TextBlock as #slfan suggests.
I think you have to tweak the generated XAML a little bit. Unfortunately Visio generates glyphs for every single character. If you want to change the text at runtime, you will have to remove this glyphs and add the required controls (e.g. TextBlock) yourself.
You can load the XAML into Silverlight with XamlReader.Load. A good description you find here: http://blogs.silverlight.net/blogs/msnow/archive/2008/10/09/silverlight-tip-of-the-day-60-how-to-load-a-control-straight-from-xaml.aspx.
All JavaScript and HTML files you can ignore, the XML-file you need to identify your controls. The ID's in the XML refer to the corresponding elements in the XAML-file.
I am looking for some control that can do following 2 :
1.highlight some of the text in different colors.
easy databind.
checked richtextbox - but it is hard to databind with it.
checked textbox but it problem to text hight light with it.
any suggestions
Use the RichTextBox - or even better the Extended RichTextBox here (it allows easy DataBinding): http://wpftoolkit.codeplex.com/wikipage?title=RichTextBox.
If you don't want to have to include another control you can create an AttachedProperty to make it possible to bind to the built in RichTextBox. Check this out here: http://michaelsync.net/2009/06/09/bindable-wpf-richtext-editor-with-xamlhtml-convertor
I want to be able to dynamically modify the image in a c# treeview. Specifically, I would like to reduce the opacity in certain cases of certain images.
I know that I can add extra icons to the imagelist that is bound to the treeview, but as cases like this add up, the extra icons will get to be too much.
Is there a way to access the image in a treeview node without completely ownerdrawing the whole thing? or if I do have to ownerdraw the entire tree, is there a template I can modify?
TIA!
If you look at your designer code you should see something like this:
this.imageListTree.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageListTree.ImageStream")));
You might be able to modify the objects within imageListTree.ImageStream and rebind it to the tree.
If you look at your resource file you should see a Base64 string within the XML file. You can probably stream that Base64 and manipulate it on the fly.