WPF - Export XAML content to file (PDF or Word) - c#

I have a pretty straightforward WPF application, but with a lot of forms, nearly 80, spread out to UserCcontrol xaml files and navigated with TabControl on a main Window file. Some of those forms contain a lot of data, but basically everything is broken down to TextBlock, TextBox, Label, Grid, RadioButton and ComboBox controls.
I am done with everything, but there is a requirement that everything at the end should be exported to a file - either PDF, or Word. Is there an easy way to do that? I don't have a requirement to have the same style and formatting. I only need the text - question and given answer, either text, or chosen option.
I have searched the web and saw many solutions, but PdfSharp was the best, I believe. However, I do have a lot of forms and it would be an overkill to map every single user control in a loop or something, to write to file. Creating a bitmap or an image and print to file would not help, since I have text boxes with scrolling and the whole text would not be visible in such cases.
What best would work for me would be a library that accepts, let's say, a user control and then prints its content on a page(s) of a file. Once again - I don't need any styling or formatting or images, just text.
Here is a small example of what one of the forms looks like, just to give you an idea:
Thank you in advance!

I've looked for similar tools and there isn't much out there, especially if you are looking for something open-source.
The most straightforward approach will be using tools found in the System.Windows.Automation namespace. That should help you write some helper functions that can capture text from all of the elements in your controls.
This link should be helpful:
https://learn.microsoft.com/en-us/dotnet/framework/ui-automation/obtain-text-attributes-using-ui-automation

Related

Code-Folding Code on RichTextBox using TreeView

I'm currently developing an IDE and Im working on Code-Folding codes now .
I'm thinking to use a TreeView as for it has a collapse and expand property but i dunno/not sure how can I implement it on RichTextBox .
Even an Initial Code showing if interaction within RichTextBox and TreeView will be much appreciated .
like:
{
}
then RichTextBox will have a line indicating till where to collapse .
Thanks a lot in advance!
It doesn't seem feasible to include a TreeView inside a RichTextBox. From my experience, building something atop the RTB is quite problematic and doesn't render the desired result without having quite a lot of quirks.
I suggest taking a look at the Fast-Colored-TextBox:
http://www.codeproject.com/Articles/161871/Fast-Colored-TextBox-for-syntax-highlighting
Or possibly building a similar control from scratch (if you too suffer from NIH) instead of attempting to extend the RTB.
If you really need your own code editor you should really think about taking Avalon Edit. It is able to rebuilt an Visual Studio Editor. So it has all you feature you need (and more).
I know it is a WPF component and not winforms. But it is quite easy to host a WPF control within winforms. So better take this route, cause trying to interweave a tree view with a rich text box will never match exactly what you like (just think about finding out the pixel size of a textline if you are using different fonts or how to determine line wrapping).

Contextual Text Editor in WPF

We are currently looking to create a text-editor in WPF (.NET 4.0) which will allow writers within our team to create movie scripts. In short, the functionality should ressemble that of FinalDraft or Adobe Story (i.e.: contextual positioning of text depending on the cursor's position and user intentions)
We are currently looking at two different solutions design-wise:
One WPF control which will act as the container, and multiple small text-editing controls which will represent rows within the script. This will allow us to position the controls using their margin, while also making binding easy. The challenge here would be the handling of multi-line selections. I was thinking of using a Listbox as the container, and each listbox item would be a custom control containing a textbox. This would require the instantiation of controls depending on the user's action. Everything would be skinned to give the impression that the user is working on a blank page.
One big textbox capable of displaying custom XML data. The challenge here would be to determine where exactly the cursor is located (i.e.: is the cursor on top of an actor's name, etc.) and positioning the text appropriately (i.e.: actor names are centered and in caps, etc.)
I recently tried implementing the first solution, but having to re-implement the whole selection behavior that is built-in in basic text boxes is non-trivial and requires a lot of work. As for the second solution, binding to my business objects will be much harder than simply instantiating multiple controls with different bindings.
Do you have any other solution in mind ?
I needed a text editor for a application once. We had a big xml file for settings and the user should be able edit those.
Turns out , if your file is large enough (+ 10000 lines) the rich text box is getting pritty slow.
As for building a gui mask : only if your user wirtes some short options like text. But is i understand you want your useres to write creativ text. This "mask" gui - "lot of small places" will make them feel like they are in the 80ties.
I suggest: Dont write the Programm , only write a Plugin to an exitings editor. Some are free like:
http://www.codeproject.com/Articles/42490/Using-AvalonEdit-WPF-Text-Editor
or an add in for word - people love Word and know Word
http://www.codeproject.com/Articles/8837/Writing-a-Word-Add-in-Part-I
And for binding data and the like: Once the text is written, the user just need to press the save button and you can parse the input for information. I would not do it on the fly as it can get pretty slow. Also you say that the information is linked so only if all the data is written you can make use of it.

Control for viewing more images in C#?

When the user clicks a button in my C# app I want to show him bunch of images so that he can pick one. I don't want to do it with file browser, I want him to be able to view little thumbnails of the images so that he sees what he is picking.
Is there any control I can use to do this?
Thanks
If you are refering to a WinForms control, I would recommend the free ImageListView control.
Works very well in my own real-world projects. Plus, the author is very responsive and the control seems to have a very high overall code and design quality.
You will need to create custom code. Or you can use a WYSIWYG Editor.
Here are 2 popular ones for .NET.
http://www.tinymce.com/
http://ckeditor.com/
Create multiple PictureBox-es in a grid formation in the form that you are creating.
Display one thumbnail in each PictureBox.
I am usually against PictureBox control usage, but in this case, you can't miss.

Writing text editor with keywords Highlighting

I am writing text editor in c# winforms and I want it to Highlight keywords.
Now richtextbox is to slow for opening big files so I am using textbox, but textbox doesn't have a property for setting the color of a selected text.
I tried to inherit from textbox and override OnPaint method but it doesn't seem to work.
I found this code and it looks great but I have no idea how to work with it.
Anyone have a solution?
I'd follow one of the following paths:
Go purchase a ready-made text editor component with the desired functionality.
Write a custom control from scratch.
The standard controls you mentioned were not designed for such advanced scenarios which require a much more elaborate processing of the content being edited.
Have you heard of Scintilla? check here or here

Preview of code-only WPF controls in VS2010 - how?

I hope I am able to illustrate the problem using a lot of images. First of all, I was no real fan of XAML (Silverlight issues, crashes in Preview, and so on...)
Now, with VS2010 the situation has become better. There are still a lot of things I like better in code, but I also want a preview in my VS.
So, take a look at the following control: It is really simple, a todo details list. The first screenshot shows the code of the control, pretty straighforward:
CodebasedControl http://img28.imageshack.us/img28/2263/invoicea49.png
There is no XAML, so obviously no preview. Of course, I could encapsulate it in another control, like shown in the next screenshot:
CodebasedControl http://img11.imageshack.us/img11/9515/invoicea48.png
But, in that case I have an additional file I do not want or need.
So I had the idea to move the init stuff inside the contructor of a XAML control. For simplicity, I used simple elements. But they do not show up in the preview...
CodebasedControl http://img99.imageshack.us/img99/5547/invoicea47.png
CodebasedControl http://img512.imageshack.us/img512/9625/invoicea46.png
Finally, I know I could use the controls in other parts of my app when creating UIs. But I am using layout manager, PRISM and a lot of other stuff, so I just want an easy preview of some specific control I created (without having to have a XAML wrapper file for each control)
Thanks for help, and sorry for the post structure, but I though with images it is better to understand...
Chris
Ok,
I found a way. Basically I am tricking VS by changing the XAML, but keeping the code-behind linked to the file. It the same like the wrapper solution, but without having a dedicated extra class or file. I am using the "xaml-infront" file for preview.
This solution only works with pure code controls, I have to do more research for mixed controls (at least I think so.. but it is enough for me for now).
Please be aware, the code behind is NOT partial anymore. It could be placed anywhere else, what I am doing here is basically only related to file-names and visual studio "readability"..
See screenshots for explanation:
alt text http://img15.imageshack.us/img15/5456/invoicea50.png
Some space for easier reading
alt text http://img186.imageshack.us/img186/1545/invoicea51.png

Categories

Resources