WPF: How to achieve visual print of UIElement into multiple pages? - wpf

I have several controls in a ScrollViewer which when printed should span multiple pages both horizontally and vertically. My current solution uses a series of scrolls (both in horizontal & vertical direction) to achieve the printing.
For this implementation to work the content of the ScrollView needs to be disassociated and added to a new ScrollViewer (the new instance of ScrollViewer is adjusted to PrintWidth and Height to achieve the print objective), as a result the original view will be emptied. To overcome this problem, I have tried Cloning the entire ScrollViewer, but this seems to fail with bindings - DataGrid is displayed empty in the cloned visual.
Is there any other approach where the visual elements can be printed, or, are there any other approach (perhaps using VisualBrush) to achieve the objective of multi page print?

Related

Container with shape like circle lines border and textblock

I am creating grid dynamically and adding 200 rows and 240 columns and adding stackpanel at each position of the grid So totally i am drawing 4800 stackpanels .Now i want to add lines circle and 3 text blocks in each of the stackpanel
Till I am adding grid add stackpanel it working fine and rendering all controls within 4 seconds which is okay .But as i started adding text block as a child control in scakpanel it taking too much time . Should I use any other better and light weight control . Or instead of adding text block can use DrawText on show text in stack panel. I further want to use drag drop functionality for stack panel so i must use only container will move along with its child elements
I think you can avoid adding the columns and the rows phase, instead of using a Grid you can simply use a canvas and handle the tabular view (rows and columns) from your code behind using the the Left and Top properties.
Beside, a canvas will be convenient to use the drag and drop functionnality. you can use for that the MouseDragElementBehavior. but then you have to deal with absolute positioning according to your Parent Window rather then the Top and Left Properites. It still realtively easy to do.
If you're using a large view where there is only a part of it displayed, you can load only the part in view.
I Hope this will be helpfull.

Animate moving a usercontrol to new grid position

I have a simple Silverlight (v5) Grid with a fixed number of rows and columns. On this grid, I'm positioning several UserControls (called myControl in this example) at specific "grid coordinates" e.g. row 2, column 1.
Occasionally, I need to move a myControl to a new grid position; I currently do this by
Grid.SetColumn(myControl, newColumn);
Grid.SetRow(myControl, newRow);
.. and this all works fine, myControl is moved to the new coordinates.
Just purely for eye candy, I'd like to animate myControl when it moves, so that it "slides" from the old grid position to the new one rather than just appearing. Is there an easy/quick way to do this?
For handling layout changes within an element to display a smooth transition FluidMoveBehavior is generally the option you would be looking for. While it won't animate things like size or visibility, it is however specifically for animating the offset of a child element moved around a parent container.
Glad you found your answer. Cheers

WP7 Managing ScrollViewer within code

Within a WP7 app I am generating a Scrollviewer within the code. This Scrollviewer has a StackPanel as its content and within the Stackpanel I have a grid.
I have not assigned any specific heights to these controls.
As far as the look and the behaviour I am after, all is fine.
I now want to position the scrollviewer to a certain point - after I have generated it and its children.
It seems that the ScrollViewer.ScrollToVerticalOffset method is what I should be using.
But I cannot ascertain the height of the Scrollviewer... both Height and ActualHeight are returning 0. I want to use this height to determine which point I should be scrolling to.
And even when I hardcode a ScrollToVerticalOffet value then it still doesn't reposition itself.
Is there a way that I can get this to position as I want, and how can I determine the height values?
thanks
Got it working ok when I checked for values in the Page loaded event... and the ScrolltoOffset seemed to work fine there too.

Silverlight 4/WPF - Nested ScrollViewer panel that scales with available screen size

In the Windows Forms world you can take a panel and set it's dock property to fill and so on with nested panels, when the user resizes the window the panels and nested panels automatically resize too. I want to achive something similar with Silverlight, here is my current structure.
Main
ScrollViewer // for body
UserControl
Grid
control
Scrollviewer // this is where my problem is
Control
The problem is I can set a size for the nested scroll viewer that looks good for 1024 resolution, but I also want to account for users that have larger resolution. If I leave it auto the content just stretches below the visible bottom line and defers to the top level ScrollViewer.
If I could achieve something analogous to how Windows Forms handles this with docking I think my problem would be solved. I must have a ScrollViewer for the nested panel and I want it to fill all visible space left. How Can I achieve this with SL4 or WPF?
[Edit]
Here is an illustration of what i'm after.
The top-level ScrollViewer allows its content to be as large as it needs to be, and adds scrollbars if that means they don't fit in the window. Its children no longer know or care how tall the window is; they just know that they've got as much space as they want.
So what is it that you want from your nested ScrollViewer? It's got all the space it needs, so it will grow to show all of its content -- there's nothing to restrict it to the height of the window. In fact, you added a top-level ScrollViewer, which specifically told it "don't restrict it to the height of the window".
If you want your inner ScrollViewer to be restricted to the window height, then take out the top-level ScrollViewer.

Silverlight: how to use a scroll viewer to wrap a list view without specifying height?

I have a control that has a list that varies in length greatly. This control appears in various places meaning that i cannot calculate its position and desired height easily.
Moreover all I want is for the scrollviewer to simply size itself according to its parent. currently it insists on sizing itself according to the content.
currently when i have a list that exceeds the height of the screen the whole control extends off the bottom and the scrollviewer shows no bar (because it has stretched to the heigth of the contents and so thinks it is not required).
I've not included code as the object graph is fairly deep.
What i am looking for is a set of conditions that would cause the scrollviewer to resize itself according to its content rather than its parent.
I have it working in a similar situation involving grids and datagrids, the unique part of this control is that there is a list containing controls.
Any ideas? I would prefer solutions that don't require use of code behind - but im really not in a position to be choosey.
Here are common reasons that come to mind that would allow a scroll viewer to size to its contents rather than to its "parent":-
It's placed on a Canvas or a StackPanel
It's assigned to a Grid row/column with it's Horizontal or Vertical alignment not set to Stretch and its content size is less than the size of the row or column.
Its ultimately upto the containing panel how it chooses to size a child element so its not really possible to dictate this completely from code inside the child.

Resources