Surface Effect in Silverlight 4 - Magnify Effect

Earlier in this series, I was talking about the ripple effect, here.  To start with magnify effect, we need to follow the same steps are before, and have to choose Magnify Effect now.  The properties screen would look like  


The Amount value determines how much to zoom. Here I am binding it to a slider.  As usual Center determines the center of the effect, and it should be given between 0 and 1.  We can get this values by dividing the expected X, Y value with the width and height respectively.  The inner radius and outer radius is about the lens effect.  It will be curved appropriately.  Here I used the same values for both, because I don't need any curves for the lens and an abrupt one.

Now we are all set, and as a final piece of code, add the following handler for Mouse Move.

private void image1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
    Point p=e.GetPosition(image1);
    p.X /= 175 ;
    p.Y /= 175 ;

Have fun with this and have the source code attached with the article.

Up Next
    Ebook Download
    View all
    View all