I am trying to implement an effect that will stretch a polygon along a line from its center point to the mouse location. I've tried various approaches with a SkewTransform and the planar angle between those two points but that isn't giving me what I want.
I am kind of assuming I'll have to go the MatrixTransform route but my linear algebra is pretty rusty.
You can either use the ScaleTransform and just apply it in one direction then combine it with a RotateTransform if the direction you need to stretch in isn't just plain x or y, or take a look at the Stretch property on the shape.
There's a good article on CodeProject that has some examples.
MSDN also has some reference material.
Related
Is there a way to take the intersection of two geometries in Silverlight (4.0)?
Background: in order to implement clipping, we need to take the current clipping area (a geometry) and intersect that with a new area in order to obtain the new clipping area.
We actually have a solution for this, but it seems awkward, or at least sub-optimal: we draw inside a canvas with its own clipping area, and whenever we need the intersection of a new clipping area, we create a new canvas with its own clipping area, and place that in the old one. We can then start drawing objects in the new canvas, and they will be correctly clipped against both.
I think you can use "Composite geometries", check this link to find how to create composite geometries.
W.r.t. the answer of Andris: unfortunately, using composite geometries does not appear to be sufficient. A GeometryGroup creates a union of shapes. To my knowledge there is no way to specify an intersection.
Note also that the fill rules are too limited to specify an intersection.
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.
I need to replicate a circular (or angle) gradient from a Photoshop comp in WPF; so far I can only find linear and radial. Does anyone know if such a thing exists, or and easy way to get get a circular gradient in WPF?
Note: I'm not asking about a radial gradient. A circular gradient is like taking a rectangle, applying a gradient and then transforming the rectangle into a circle.
Check this question for a new and a bit more complete answer to this question.
While I've never done this before (so I don't know what's involved) you could implement a type that inherits from GradientBrush. I don't think this is trivial though.
I've also not worked with Photoshop circular gradients, but from your description I can't help but think that you could at least approximate it using a LinearGradientBrush and then transforming the result - perhaps using a MatrixTransform.
Sorry that I can't give you concrete answers, but maybe these suggestions can point you in the right direction.
Are there any examples on the internet of silverlight animation which can do the following:
A rectangle zooming in
A rectangle going down from a certain position on the x axis to a certain position on the x axis
I looked on silverlight.net but couldn't find these examples (which are quite rudimentary). Anyone know where I can see an example with source for this?
Thanks
Do a ScaleTransform for the zooming effect and Translate transform for the move effect. I am sure you can find out lot of examples in a search for "Silverlight Animation". It doesnt matter it is rectangle or any other UIElement
http://www.wynapse.com/Silverlight/Tutor/Clipping_Silverlight_Animated_Rectangles.aspx
http://www.developerfusion.com/article/7303/have-you-seen-the-silverlight-more-silverlight/2/
I've seen examples in silverlight where the achieve a effect using 1 of 2 ways:
Two image objects, both
displaying the same image, but the
bottom one rotating it 180 degrees
and applying a gradient image
opacity
A MediaElement object and a VideoBrush element.
I have a series of path objects, rectanges, etc which I would like to apply a reflection affect to. Is there a more elegant solution other than copying my objects manually and rotating them? Unfortunately the VideoBrush object only works on MediaElement objects, but is there something else I can use?
Not in Silverlight, in WPF you have a VisualBrush which can help with this but Silverlight doesn't have one in version 2. Just to be clear though, it's not a rotation it's a negative ScaleY on a ScaleTransform. The easiest thing is to put everything into a UserControl and then use two UserControls with one having a ScaleTransform and an OpacityMask on it.
For a good example, please see the following blog post from Mike Snow.
http://silverlight.net/blogs/msnow/archive/2008/09/04/silverlight-tip-of-the-day-36-how-to-create-reflections-and-shadows-for-images-and-text.aspx