Printing/Previewing WPF RichTextBox - ApplicationCommands.PrintPreview? - wpf

I'm really loving the WPF RichTextBox, and all of the out-of-the-box functionality it comes with...but printing is something that I'm having trouble with. I can print (from code) using a PrintDialog and passing in my RichTextBox as a Visual (or by using the "Document").
But my question is, is there a simple way to use the application commands:
ApplicationCommands.Print
ApplicationCommands.PrintPreview
With a WPF RichTextBox? Also, how would I go about letting the user change the page layout and such?

Take a look at http://blogs.msdn.com/llobo/archive/2007/01/24/printing-richtextbox-content-find-the-idle-printer.aspx

Related

vb.net - Can I load a wpf form into a canvas/grid control?

I trying to see if its possible to load a form into a canvas or grid control in wpf with vb.net.
I'm not very familiar with WPF at all, usually working with Winforms more than anything else, however I need to take advantage of the far superior transparancy options offered by WPF for this current project, so need to see if I can crack this.
In Winforms, I'd normally have a panel (call it contentpanel or mainpanel etc) and then whenever I needed to I could easily load another form into that panel dynamically and keep everything neat and tidy in one form when presented to the user, so something like...
dim newforminstance as form1
newforminstance.toplevel = true
newforminstance.topmost = false
contentpanel.controls.add(newforminstance)
newforminstance.show
That works a treat in Winforms; Is there a similar way to achieve this functionality in WPF?
Thanks in advance.

Simple XAML viewer in WPF

I need to write XAML of a WPF control to string. I used XamlWriter.Save(). It works good. Also I need to format, indent and show the string in a editor (read only) like VS Xaml code view. I dont know how to do this.
Please share your valuable ideas.
You can save to a XmlWriter instance, create a XmlWriter, create a XmlWriterSettings instance and set the Indent property to true and set this on your XmlWriter. That way you should have the indentation.
Now for a control to display it, you could use the RichTextBox in wpf, or look for a custom control around the web.

WinForms "mini-windows"

I need to create some mini-windows, like the ones shown in the image bellow, in my winform main form.
It would be nice if they could be draggable, resizable, and, mainly, closable.
How can I approach this design? Has anybody already seen some control (with code available) implementing something similar?
alt text http://img716.imageshack.us/img716/5765/imagea.png
A normal Form works fine for this. Set its FormBorderStyle to either FixedToolWindow or SizableToolWindow as desired.
If you want to keep your floating windows inside your main window, use MDI (Multiple Document Interface). Here is a tutorial (Google can find you many more).
Have you tried just setting the FormBorderStyle property to SizeableToolWindow?
Is that what you're after?
You can create them as resizable and draggable custom controls.
You could use my example at:
http://hourlyapps.blogspot.com/2008/07/resizable-and-movable-controls-c-net.html

What is the best substitute for FlowDocument in Silverlight?

I'm porting an application from WPF to Silverlight and was saddened to read of the lack of FlowDocument support.
What is the best way in Silverlight then to display text with markup?
I just need the basics, e.g.
bold
italic
hyperlink
colors
font sizes
Added:
I don't mean a RichTextBox (as in the Vectorlight demo) but a way to format text on the application surface itself, like I can do with FlowDocument in WPF:
(source: deviantsart.com)
In Silverlight 3 Vectorlight's Free RichTextBox can do a pretty good job of what you need using HTML.
In Silverlight 4 you have the option of using the RichTextBox to represent your content.
If you do get something like that up and running, msg me and maybe we can collaborate on bringing my "BindableFlowDocument" into the world of Silverlight. ;)
edit - wow, I must have gotten mixed up - my original answer was way off
Inline with the comments of SL4 RC's RichTextBox (RichTextArea, circa SL4 Beta), and with your example of importing marked up text, the SL4 RC RichTextBox will allow for an import of XAML formatted text - like string richText = MyRichContent.Xaml; on this page: http://timheuer.com/blog/#richtextbox. Details are listed here: http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.xaml(VS.96).aspx.
Just use the RichTextBox in Silverlight 4.0

WPF search windows - like tabPages in tab control

I have idea to implement my wpf windows like TabPages in tab control. It is possible to do that dynamically in c# code.
In Example i have Menu in main window. Some Menu items calls search type windows. Is it possible to do such a thing in C# code (SomeMenuItem_Click): this code adds new tab in tabControl of main window.
If there are no search windows called -there is no tab's shown, if there are many search windows called - there are many tab's.
So how do I code this?
And whats the technique with the windows? I suppose that my search type windows must be implemented like some UserControls. I think its no a good idea to implement that like simple wpf windows. I have tried to do that by using Marlon grech "Blend like UIs using DOCKY", find at:
http://marlongrech.wordpress.com/2008/01/29/create-blend-like-uis-using-docky/
But I failed, dont find the way how to add controlls in code dynamically, not in xaml.
I would appreciate code examples to illustrate how to achieve this.
Is it possible to do such a thing in C# code (SomeMenuItem_Click): this code adds new tab in tabControl of main window.
Yes. The basic pattern is:
TabItem newItem = new TabItem();
tabControl.Items.Add(newItem);
You'll obviously need to set the relevant properties of your tab item (such as the Header and Style) but that should get you started.
You'll then need to create any controls you want to show and add them to the tab item itself (or more correctly - a container within the tab item).

Resources