WPF ensure transformed content is visible - wpf

Does WPF provide a control that automatically transforms contained content to be visible?
I can compute things manually, but I'd rather work with existing Dependency Properties.
I'd like to add content to this hypothetical control, rotate the content, and have the parent perform additional transformation to make sure the entire content is visible.
(Similar to Smallest possible bounding box for a rotated image)

Put the whole content into a Viewbox.

Related

WPF - Displaying thumbnails in a grid as they arrive from an external source

I recently wrote a routine that displayed a grid of images from files in a folder. I used a vertically-oriented ListBox where each row in the ListBox was a horizontally-oriented StackPanel of the images. I just had to walk the folder tree and populate the StackPanel. It was simple, quick and easy to implement.
Now I have a new requirement. I'll be receiving the images one-at-a-time from a piece of factory equipment that will be sending one every few seconds and I need to display it as I get it. I still need to display these in a grid but the images start from the lower left and proceed to the right until a row is filled up, then we start a new row directly above it. We WILL know at the start the final dimensions, but it may be more than we can fit on a screen so scrolling will have to be enabled.
What are the right controls to use for this in WPF? Is there a way to reuse my ListBox/StackPanel scheme or are there more appropriate controls for this? Remember, the images must be displayed as I get them - I can't fill up a whole StackPanel and then do a
listBoxImages.Items.Add(myStackPanel)
... or can I - can I add an empty StackPanel to a parent and then populate one image at a time afterwards? What's the right way to go about this?
Based on the fact the number of images is known at the start of the routine, I would create a view model with a collection of collections.
The first is an observable collection with elements for each row, inside the element is another collection for each column. This can be bound to an items control where the content template has a second items control with horizontal orientation.
Then, as your images arrive, you start to fill the last element first with your image references and work back up. That should create the desired effect. Not sure how that works with scrolling as you effectively want the last element to be in view first, so scrolled to the end.
Another option, using a single collection is to bind to an items control with a uniform grid panel template. This can be wired up with a DataTemplateSelector which when the data is null, displays an empty template, otherwise shows an image box. This will allow you to again add elements to your collection in any order and it mirror on the UI.
An example of the data template selector can be found here. Or search SO.

Replacing the WPF rendering pipeline

WPF doesn't appear to convey visibility information during rendering so it does no culling and, consequently, performance can be awful. So I'm interested in the idea of circumventing WPF's normal rendering pipeline in order to replace it with a more efficient one.
For example, given a scroll viewer containing a grid of controls I'd like to precalculate the locations of the controls in the grid in order to render only potentially visible controls given the visible region within the scroll viewer. So I'd replace the scroll viewer's renderer with one that passes that visibility information and then replace the grid's renderer with one that uses that visibility information to cull controls that lie completely outside the visible region.
Is this possible and, if so, how might it be accomplished?

How do Transforms in WPF work?

I recently used a TranslateTransform in my WPF application to implement dragging a UserControl across the screen. There is a new bug in that after the first time you drag it somewhere else on the screen, when you click on the "Title bar" on the control, it jumps back to where it was originally displayed. It will still follow the mouse, but that initial jump is disconcerting.
I don't know what's going on, but this got me to wondering. Since WPF controls don't have a left or top property of their own, unless you put them into a Canvas, and those are attached properties anyway, just what properties are being modified by the TranslateTransform?
WPF's layout and render passes have intrinsic knowledge of transforms. By modifying the X and Y properties of the TranslateTransform, you're causing the layout/render pass to take those new values into consideration when positioning the associated FrameworkElement.
To put it another way: the TranslateTransform is not modifying other properties, but by modifying its properties you are triggering another layout/render pass and thus affecting the on-screen positioning of the associated FrameworkElement.
Read here for more information.

Wpf panel layout - one child, several positions

I am working on a WPF panel derivative with custom layout logic and sometimes it might be that component should be visible in two places, when following that layouting logic. Both instances of the same component will be partially cropped. Is it possible to do this - lay out a child component in two different places during the arrange pass?
I think that the panels behaviors are for arrange items in a view, and not for copy the items. I think this is not possible. If you copy a visual element then it will not be the same. If you want get this effect you may use a VisualBrush and paint some region with that, and set to the brush the control that you may want to copy. Using VisualBursh you will see a control copy, but you will not be able to modify it. The other way is using a custom control for making this effect. Other way could be using two different custom panels, both with the same items source (in the case that be the ItemsPanel for some collection).
Hope this answer helps to you...

Silverlight control layout update in runtime

I have a silverlight control that has a few element such as: Image, TextBox and a TextBlock.
The application shows a list of the same control and the controls are placed in a specific layout, in grid with rows and cols.
Now,
I would like to be able to modify all the controls layout and arrange the element differently (preferred animatedly) without reloading the control.
Does anyone know how to do so?
Thanks,
Ronny
Use the States pane in
Expression Blend 3 to define different
layouts.
Use the GoToStateAction for the objects/events that you want to trigger the change or call VisualStateManager:GoToState(this, "NewState", true) from your code behind to switch layouts.
Use FluidLayout (the wave-shaped first button first for the State Group) to animate the change from one grid col/row to another.

Resources