WPF animated stack panel - wpf

I'm in the process of creating an ItemsControl that will have something similar to a StackPanel for its ItemsPanel. However, I want the user to be able to rearrange items in the panel, and have them animate to their final positions like this:
I've done some searching, and a lot of the examples I have found that do something similar, implement the animations by setting the desired position of all items to 0,0 and applying a RenderTransform storyboard in the Panel.ArrangeOverride method to offset each item vertically.
Whilst this works, is this the correct way to be doing it? Doesn't this mean the controls won't take part in normal layout as they're all set to 0,0?
Will this have side effects?
I was wondering if I should use the above method for the animation, and then when the animation ends, do another final invalidation of the arrange layout, but this time using actual positions instead of render transforms?

Related

Animate wrappanel items repositioning

I'm trying to create an animation like the text zoom animation that exists in the wii news channel. See this at 0:45 to an example.
My current code is to take a string, split it into a string[] between the spaces, create a textblock for each word, and inserting it into a List of TextBlocks.
After that, I need to put it as an ItemsSource of a WrapPannel, and change the fontsize of each textblock to generate the zoom effect. This will make the correct positioning, but without any animation.
I also searched about FluidMoveBehavior, but I don't know how to apply this to my situation.
How can I animate the repositioning of the items into the wrap panel? My approach is the best way to do that?

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

Image glimmer or sparkle animation

I've been searching for awhile, but haven't been able to find anything. I'd like to be able to add kind of a glimmer or sparkly animation on an image element in wpf.
Essentially the effect here I'm after here is the same that you get with trading cards that are "foil's".
I'd like to have an image, and then be able to add this animation to it at will. I'm thinking maybe some kind of user control, or template possibly. Hopefully generic enough that I can just toss an image at it and it will just overlay the image and run.
Any ideas?
A simple construction that easily can be turned into a control is by nesting the image in a Grid and adding a second Grid (on top) as a sibling.
De second grid can be given a linear gradient brush that is primarily transparent but does contain a white glimmer.
This brush can be animated; you could move it and change the opacity of the grid/brush.
This way you do not change the image.

Silverlight MouseDragElementBehavior. How to rearrange items after drag and drop?

I have stack panel with custom controls in it. User can add or remove the items.
I have attached MouseDragElementBehavior to each item. So now user can move them within the stack panel.
However the items now are arranged on arbitrary manner. Is a mess really. They stay where the user left them.
What I need now is to make them to be stacked as the stack panel supposed to be... Nicely one by one...
So I need to simply let user change the order of items by using drag / drop operation but items has to be stacked precisely.
There is DragFinished event, but I dont really see how the Behavior moves items. I thought it is Margin it changes but margins stays 0... I dont know what to do next.
Appreciate little help.
MouseDragElementBehavior does its work using a Transform on the RenderTransform property of the attached element (i.e. the one the behavior is applied to) (the exact type of transform depends on the state of the RenderTransform property but it will either be a TranslateTransform or a MatrixTransform).
The transform is not reset when you finish dragging (nor would you want it to be because the element would snap back to its position in the StackPanel when you started dragging) and this is why the element stays where "the user left them".
To change the items position in the StackPanel in the way you are talking about you will have to use the DragFinished event. What you probably want to do is work out where in the StackPanel the element will end up (as a result of the drag, i.e. which element in the panel it will "push" down) then create an animation to animate the element from its current position (where the user released the drag) to that final position in the StackPanel and another animation to move the "pushed" element in to its new position in the StackPanel (VisualTreeHelper can probably help here (I think)). Once those animations are finished just set the new index within the StackPanel for each item and remove the RenderTransform translation.

How can I animate a transition when moving a child from one panel to another in Silverlight

I would like to animate a transition when moving content between two panels. I am getting a bit map image of a detail record and docking it as a thumbnail in the panel below. The docking area is in a footer grid and the content detail is in another grid that sits above the dock area (the dock and the main content area live in separate rows of the root layout control - another grid).
I have tried implementing this with a ScaleTransform and a TranslateTransform, simultaneously shrinking the image and moving it towards the footer control. When it moves into the footer control, it gets clipped even though the image Canvas.ZIndex property is set to a very high number. Eventually the thumnbail will need to be a child of a StackPanel that sits inside the footer grid.
Thanks for your consideration and help.
I had a similar problem (clipping) with a WPF animation I had. The problem was that the owner of the animation needed to be a parent of both containers for the animation to work (in my case I made it the actual window holding the containers).
Without any code, I can't see if that is your problem, but I thought I would throw it out there.
You can see my code where I animate moving from one container to another here:
http://wiassistant.codeplex.com/sourcecontrol/changeset/view/36638?projectName=WIAssistant#924851
(See the AnimatePaneBox method at the bottom of the file.) This may or may not be useful to you.
I've done something similar by creating a Canvas that sits over the top of both containers, using a WritableBitmap (if necessary) to create a rendering of the object that you're moving and attach it to that Canvas, animate the bitmap (translate, scale, opacity, whatever), and then pop the new object in under it at the end of the animation. It can be brittle if your controls need to be able to move or resize, but in most of my circumstances it's been a reliable hack.

Resources