Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Sorry,in fact,i use a Rectangle's RippleEffect to Render a water reflection.
HTML
<Rectangle x:Name="imgShader" RenderTransformOrigin="1,0.5" Height="256" Width="1024" MouseMove="Rectangle_MouseMove" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown">
    <Rectangle.Fill>
        <VisualBrush Visual="{Binding ElementName=gdBackground}" />
    </Rectangle.Fill>
    <Rectangle.RenderTransform>
        <ScaleTransform ScaleY="-1" />
    </Rectangle.RenderTransform>
    <Rectangle.OpacityMask>
        <LinearGradientBrush StartPoint="0,0"
                             EndPoint="0,1">
            <GradientStop Offset="0.3"
                          Color="Transparent" />
            <GradientStop Offset="1"
                          Color="#44000000" />
        </LinearGradientBrush>
    </Rectangle.OpacityMask>
    <Rectangle.Effect>
        <ee:RippleEffect x:Name="effectImgShader" Frequency="0" Center="0.5,0.81" Phase="0" Magnitude="0.03"/>
    </Rectangle.Effect>
</Rectangle>


and when mousemove on the Rectangle, I change the RippleEffect's Center to make it likes something in the water;

C#
private Point effectCenter = default(Point);
private void Rectangle_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Point position = e.GetPosition(this.imgShader);
            this.effectCenter.X = position.X / this.imgShader.ActualWidth;
            this.effectCenter.Y = position.Y / this.imgShader.ActualHeight;
            this.effectImgShader.Center = this.effectCenter;
        }


but when I move mouse, it doesn't show effect because the Rectangle didn't refresh, so I use a WriteableBitmap in it to make it can use Invalidate() to repaint.

finally, I just want to refresh Rectangle when mouse moves.
Posted
Updated 17-Oct-13 7:35am
v3
Comments
Sergey Alexandrovich Kryukov 16-Oct-13 2:49am    
Not quite a valid question. You need to tell us what are you trying to achieve, not what methods you are trying to use.
—SA
Elan.Cao 17-Oct-13 3:31am    
sorry,i improved my question,can u help m? thanks!

1 solution

perhaps you should use RenderTargetBitmap instead of WritableBitmap: http://msdn.microsoft.com/en-us/library/System.Windows.Media.Imaging.RenderTargetBitmap.aspx
 
Share this answer
 
v2
Comments
Elan.Cao 17-Oct-13 3:32am    
sorry,i improved my question,can u help m? thanks!
Irina Pykhova 17-Oct-13 11:20am    
your sample works for me with the standard BlurEffect. So perhaps the problem is in effect you use. Probably it is not updated on changing center, or maybe some properties should be set to something else.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900