I have a silverlight application which consists of a few tabs, which I would like to print or to generate PDF containing these tabs.
I tried to use StackPanel to add each tab and then use PrintDocument to print what I see, but there is a problem because there are too many tabs, so they don't fit in the size of A4 document.
And more, when I resize the browser to a smaller size, only the visible part of the content gets printed.
Is there a different method to print all the content in one document or PDF?
The PrintPageEventArgs in the PrintPage handler contains the size of the paper so you can calculate how much can be printed on a single page.
Printing (a part of) the visual tree has its disadvantages; what looks good on screen might not be good for paper, especially if scrolling and sizing are involved.
A solutions is to design one or multiple Views for printing and simply bind the same ViewModel to the PrintView. A bit like the special CSS for creating a print version of a web page.
If the content doesn't fit you should use more pages.
This article by Charles Petzold is worth reading too
Related
I have a web page that uses em units to allow it to size automatically to any screen size, so the page displays fairly well on mobile devices. I notice, though, that the iPad and iPhone (those are the only mobile devices I've checked so far) wrap blocks of text wherever they feel like it and this breaks the formatting if I've inserted spaces to line up lines. For example, I might have the text
1. This is the first sentence of some text
that wraps to a second line.
There's a Return at the end of "text." on the first line and then the next line has spaces at the beginning to get "that" to line up under "This." But now if an iPad decides to wrap this text after "some" the formatting is destroyed:
1. This is the first line of some
text that wraps to a second line.
Is there a way to tell mobile browsers to not wrap the text themselves and just honor the Returns in the text?
Thanks
Have you tried wrapping your text in <pre> tags ? it will respect your formatting.
Anyway, having the text reflow is preferable since it can rearrange and adapt to any screen size, there is nothing more annoying than having to scroll to the end of the lines to read the text.
If you want to have greater control of text output you will have to address each screen size individually, so I’d use the media element in CSS so you can apply different style depending on screen size.
google “screen size in css responsive” an you will see lots of resource about it.
Looking at your example text more closely, cold you enter <li> tags? so that the numbering could be placed outside? using list-style in CSS? I mean, if your problem is only with list numberings, maybe that can do it.
Best regards.
First time working on a GUI project.. and first time doing work on Windows so apologies in advance if this is a really noob question.
I'm taking baby steps into windows programming starting with vb.net WPF. Working in Visual Studio Express 2012.
I'm trying to work out how I can scale all the elements in a window with the window itself.
So for example, I'd create a window, say 1280x720, and place some images in the window. Say one at the top and one in the corner. (this is a basic media based application)
When I resize that window, I want the entire window to scale with it, so image 1 & 2 will get larger if the window gets larger, however this has to happen proportionally so that if I make the window a lot bigger in one direction one image can't overlap the other. Imagine the window is an image and I'm trying to resize it. (The overlap thing is the closest I've gotten to getting this working in my current attempts).
The layout in produciton will be more complex, comprising of mediaelements (video), images, text etc and all must scale accordingly.
This isn't something the user interacts with and so there are no form elements etc, and so I don't need form fields etc to stay the same size throughout scaling. I just need everything to scale like I'm scaling a picture. If for example I displayed this 1280x720 (16:9) layout on a 1920x1080 screen, maximised it should look identical only larger.
Hoping someone can point me in the right direction with this.
What I've tried so far- the few articles I did find on google relating to this (I may well be searching the wrong things) lead me to put all the elements in a viewbox, this lead to the overlap I mentioned earlier.
Ideas ?
I think you could use ViewBox container. The basic idea is as follows: ViewBox scales its content just as if it was an image scaled. This seems to be the closest result to what you've described in your question. Just put a Grid with absolutely-sized columns and rows into the ViewBox and set its Stretch to be Uniform:
<Viewbox Stretch="Uniform">
<Grid>
<..>Your controls, MediaElements, etc
<Grid>
</Viewbox>
You could also combine it (or entirely replace) with (e.g.) Grid Container : it gives you an ability to specify cell width and size usign star-syntax which is similair to html's percent syntax.
Another way is to use the DockPanel.
All-in-all there are plenty ways to achieve something similair and the way to go largely depends on the nuances of your particulair requirements.
Have a look at This tutorial to see a good overview of WPF containers and how to use them.
In my application, I'm generating a FlowDocument with several paragraphs of text.
Using a FlowDocumentScrollViewer , I can display the document in my UI. If the document is too long for the available space, the FlowDocumentScrollViewer does it's job and introduces a vertical scrollbar. All good.
If I use a FlowDocumentPageViewer the response to show additional pages of text, also as designed.
However, what I want in my application is for the viewer to grow wider.
So, for a short document, the viewer is narrow (say, around 360 pixels with one column of text), but for a longer document the viewer is wider (say, around 720 pixels with two columns of text). An even longer document would expand to three columns, and so on.
I've seen a number of WinRT applications that do this kind of thing - The New Zealand Herald has one app. But, I'm working in regular WPF and have ended up stumped.
How can I display a FlowDocument so that it's all visible at once - no scrollbars, no pagination, just multiple columns of text stretching across?
Why do I want this? I'm showing several disparate pieces of information on a single page, and I want to have a single horizontal scrollbar for panning across the lot, not separate scrollbars for each piece. For example, I've got my ListBoxes working this way by using a WrapPanel as the ItemsPanelTemplate - when there are too many items for one column, another column opens up and the listbox gets wider to accomodate.
I am new in WPF if there is something wrong please co-operate.Here i require some idea from experts.
I am working on one application in which i have to show some content on WPF form after filling the fields present on the form.On the same form i also have a print option.
Check this image.This is my form here part in the red block is generated at runtime.When i click on the print button it only show the visible part on the paper and skip the remaining part.
Problem :
How i can move the remaining part of the form which is under scroll to next page when i click on print.
For example in the given image we can see only 2 bulls eye completely and next 2 partially.How i can shift this remaining part to next page only when i click on print.
The answer is quite easy : don't rely on your window to do the printing, but build the visual you want then print it.
For instance, you must have a function that creates dynamically the circles and so on, then adds them to a Panel. What you might do is to print the Panel.
Or if you prefer, you might build Dynamically a new window, where you put all the Data you want printed as you want, then print the window. The advantage of this method is that it is more flexible for the content (if you want a header/footer) and also you can watch the content easily for debug. Note that even if the Window content is dynamic, you can have a base window for printing that avoids you to do too much xaml with code (expl : you might have TextBox bound to a PrintTitle property that you setup in the constructor of the Print Window...).
Notice that visual that were not rendered on screen will not print. Be sure, to avoid the common issues, to have a look at this article from this great site, switch on the code, here :
http://www.switchonthecode.com/tutorials/printing-in-wpf
Edit (reply to the question in comment):
1) If you have fixed number of bulls eyes, just make one Window for that number and Print it, this is waaaay easier.
2) To put Visuals in pages instead of rows, you'll have to rely on page Width/Height. What matters is the size of your control vs size of page. In the example, they build (in OnRender) Controls having LineHeight, LineWidth as size. Do the same : Try to put as many line of control as you can such as
(Control Height + margin )*NumberOfControlPerPage < Page Height.
Then you have to change OnRender to render controls instead of Rows made with rectangle+text. Pack your controls two by two in Horizontal StackPanels Then pack those StackPanel into a vertical StackPanel, then render. You have to keep track for each page which control was rendered last, then resume rendering at the following control.
Please follow this link.This is the basic which i got after searching in web world.Using this basic detail you can do any thing with print in WPF
I have a WPF page that has 2 ContentControls on it. Both of the ContentControls have an image, one being much smaller than the other. When mouse over the larger image I want to show a zoomed in view on the smaller image. Something very similar to this: http://www.trekbikes.com/us/en/bikes/urban/soho/soho/.
I think I want the larger image control to send out something that actually contains an image - which the smaller image control would pick up and display. Would this be a good place to take advantage of RoutedCommands? Can I pass along an image like that?
RoutedCommands seem a bit misplaced in this case... you'll want the mouse to respond smoothly and the last thing you want are commands to be fired off here and there.
You're probably better off using a VisualBrush. While Ian Griffith's example here is a magnifying glass (an early canonical VisualBrush example in WPF) you could easily adapt it to show a portion of your image.