WPF window 子視窗反饋效果(拉動/漸層)

來源:互聯網
上載者:User

標籤:animation   漸層   Owner   and   ref   var   mil   視窗   present   

 當子視窗顯示後,點擊子視窗外部,需要有反饋動畫。

實現:

1.事件捕捉

每次點擊子視窗外部,即母視窗時,事件捕捉如下

HwndSource hwndSource = PresentationSource.FromVisual(this.Owner) as HwndSource;//視窗過程

hwndSource?.AddHook(WndProc);

 也可以調用WindowInteropHelper,擷取母視窗控制代碼。

var hwnd = new WindowInteropHelper(this.Owner).Handle;
if (hwnd != IntPtr.Zero)
{
  var hwndSource = HwndSource.FromHwnd(hwnd);
  hwndSource?.AddHook(WndProc);
}

事件中,啟動動畫

 private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)    {         if (msg != 0x20) return IntPtr.Zero;         if (lParam.ToInt32() == 0x201fffe) _storyboard?.Begin();         return IntPtr.Zero;    }

 

2.動畫設定

視窗抖動 動畫

            var scaleXDoubleAnimation = new DoubleAnimationUsingKeyFrames();            var scaleYDoubleAnimation = new DoubleAnimationUsingKeyFrames();            scaleXDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)),Value = 1.0});            scaleXDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100)),Value = 0.9});            scaleXDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200)),Value = 1.0});            scaleYDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)),Value = 1.0});            scaleYDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100)),Value = 0.9});            scaleYDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame            {                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200)),                Value = 1.0            });            Storyboard.SetTarget(scaleXDoubleAnimation, window);            Storyboard.SetTarget(scaleYDoubleAnimation, window);            Storyboard.SetTargetProperty(scaleXDoubleAnimation, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleX)"));            Storyboard.SetTargetProperty(scaleYDoubleAnimation, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleY)"));            _storyboard = new Storyboard{Children =new TimelineCollection { scaleXDoubleAnimation, scaleYDoubleAnimation }};

 

視窗陰影 動畫

            var animation = new DoubleAnimationUsingKeyFrames();            animation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)),Value = 0});            animation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200)),Value = 50});            animation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(400)),Value = 0});                        Storyboard.SetTarget(animation, window);            Storyboard.SetTargetProperty(animation, new PropertyPath("(FrameworkElement.Effect).(DropShadowEffect.BlurRadius)"));            _storyboard = new Storyboard            {                Children = new TimelineCollection { animation }            };

 

WPF window 子視窗反饋效果(拉動/漸層)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.