Move the WPF mouse over the image to increase, remove and restore, and click the trigger event effect.

Source: Internet
Author: User
<Grid>        <Canvas x:Name="LayoutRoot">            <Image Cursor="Hand" MouseLeftButtonDown="imgLogo1_MouseLeftButtonDown" MouseEnter="imgLogo1_MouseEnter"                    MouseLeave="imgLogo1_MouseLeave" Canvas.ZIndex="1" x:Name="imgLogo1" Canvas.Left="100"                    Canvas.Top="60" Height="100" Source="Image/Picture.jpg">                <Image.RenderTransform>                    <ScaleTransform x:Name="LogoScale" CenterX="90" CenterY="96">                    </ScaleTransform>                </Image.RenderTransform>            </Image>        </Canvas>    </Grid>

  

 public partial class Window8 : Window    {        public Window8()        {            InitializeComponent();            timer = new System.Windows.Threading.DispatcherTimer();            timer.Interval = TimeSpan.FromMilliseconds(50);            timer.Tick += new EventHandler(timer_Tick);        }        private System.Windows.Threading.DispatcherTimer timer;        private ScaleDirection scaleDirection ;               void timer_Tick(object sender, EventArgs e)        {            AdjustScale(scaleDirection, LogoScale);        }        void AdjustScale(ScaleDirection scaleDirection, ScaleTransform scale)        {            if (scaleDirection == ScaleDirection.Down)            {                if (scale.ScaleX < 1.3)                {                    scale.ScaleX += 0.05; scale.ScaleY += 0.05;                }                else                    timer.Stop();            }            else            {                if (scale.ScaleX > 1.0)                {                    scale.ScaleX -= 0.05;                    scale.ScaleY -= 0.05;                }                else                    timer.Stop();            }        }        enum ScaleDirection        {            Up,            Down        }        private void imgLogo1_MouseEnter(object sender, MouseEventArgs e)        {            scaleDirection = ScaleDirection.Down;            timer.Start();        }        private void imgLogo1_MouseLeave(object sender, MouseEventArgs e)        {            scaleDirection = ScaleDirection.Up;            timer.Start();        }        private void imgLogo1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)        {            MessageBox.Show("test");        }    }

Original article: http://www.csharpwin.com/dotnetspace/10339r6936.shtml

 

Loading editor...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.