Filling a Rectangle at different levels with Silverlight Animation? - silverlight

I am very new to Silverlight. I have a question on Animation. My requirement is, a rectangle should have different levels of fill indication. More clearly say, my rectangle is half filled initially, it has to be either increased/decreased with animation.
Can anyone help me out how can I do this in Silverlight animation?

draw a 2nd rectangle inside the 1st rectangle. adjust the height of the 2nd rectangle to fill up/down.
now mark my reply as the answer.

Related

Shapes Clipping

I'm having a problem that's driving me crazy for a couple hours...
Situation:
I am drawing a shape - ellipse,
then im creating a new brush - from an image,
I apply the brush to my shape,
and then I rotate the shape..
The problem is: Everthying is displaying correctly - but...
As soon as I drag the shape to the edge of the window - thats where the formular ends,
it's starting to cut of some parts of the shape.
It's simply not drawing the part that should be not visible, because overflowing the form.
But in my case, I've rotated the shape, so it's cutting the wrong part of it.
This is what it look's like. Is there a way to kinda "reset" the cliping.. Or another solution...
Solved It.
Set the parent element's width and height larger then the window is (its was HorizontalAlignment.Stretch) before.
Now you'll never reach the cliping edge of the parent

WPF Height Animation - Direction of Height

I am creating an app for the Microsoft Surface. I have a WPF control rotated 180 degrees using rendertransform so that people on the other side can use it. There are two of them, one rotated, one not. When a user selects a tab on the control, the control grows to accommodate the tab size. On the one that's not rotated, the height animation works correctly, growing "upward" toward the "top" of the screen. The rotated one grows in the same direction, toward the top as well, but it need to grow on the opposite direction. Both should grow towards the center of the screen.
Setup (They are legends on a map):
<SurfaceWindow>
<Canvas>
<UserControl />
<UserControl /> // rotated
<Map />
</Canvas>
</SurfaceWindow>
Is there a way to control the direction of a height animation?
Thanks,
Andrew
You don't need two controls : just one with, say, a 'Flipped' property (or a dependency property to use it in design time). When Flipped is True, you should set the rotation on your control and the VerticalAlignment to Top. when false, no rotation and VerticalAlignment to Bottom.
Solved.
Used LayoutTransform instead of RenderTransform
eg
Legend2.LayoutTransform = new RotateTransform(180);
instead of
Legend2.RenderTransform = new RotateTransform(180);

Animation in WPF query

I'm playing with WPF for the first time in an animation/graphics context, and I am wondering how you'd move sprites around. I googled and came up with this example, but the animation is done by increasing/decreasing the margins and padding.
My question is, is this normal? I would have thought you'd do animation by changing the x and y co-ordinates of a sprite, not its padding.
Position and Margin are the same thing. Position is the distance to the edge of the screen, or the egde of the window. Margin is the same thing.

WPF Clipping Problem

I have a UserControl which has a quadratic Image as a Child. This Image is at the bottom of the UserControl, and half of it is clipped (e.g. the Control's Height is 400, Image's height is 200 and it is set to y=300).
Now, When I rotate the Image, it is still clipped like the way it was first. Like when rotating around 90 degrees, I suddenly have an Image which is only 100px wide.
It seems like the original clipping which was made because of the bounds of the UserControl, are applied forever.
How do I solve this problem? I hope I explained my problem understandable ;)
How are you rotating the image? If you are rotating using a RenderTransform, then WPF does not re-render what was already displayed on the screen - it simply rotates the pixels.
Instead, rotate the image using a LayoutTransform; this forces WPF to re-render the control given the new area it occupies, which should eliminate the clipping you see.
You can also call InvalidateMeasure() after applying render transform.

WPF Canvas: centered origin, scaled axes (and y inverted), responding to mouse events

In a simple code-only WPF application I'm writing, I would like to have a custom Canvas.
I've found questions similar to this one here in StackOverflow, but couldn't find exactly this one, nor a simple way to adapt another answer to my specific problem (please note that I have not much experience in WPF).
In my canvas, I'd like it to have the following properties:
the point (0, 0) is on the center of the Canvas;
the x-axis points to the right;
the y-axis points to the top;
the point (1, 0) is about 1 inch to the right of the origin; and
in every event, the position of the mouse is given in the coordinate system defined above.
In this answer, Ray Burns propose a very simple solution to my first 3 points. It is trivial to modify that code so that it deals with my point number 4 as well (change 1 and -1 in the RenderTransform to other constants).
However, that very simple and excellent solution for many problems is based on setting width and height to 0, and centering the canvas on its container. Therefore, there's no canvas to capture events like a click, so this solution won't handle my fifth property.
What's the easiest way to achieve this? Inherit from Panel and do everything by hand? Inherit from Canvas, intercept every event and modify the coordinates?
Put Canvas inside a Border. Border has mouse events. Another case is to place Border on the top of the Canvas.

Resources