Apply animation on WPF control visibility change

匿名 (未验证) 提交于 2019-12-03 01:17:01

问题:

My xaml is

      some controls here in a horizontal strip , by default its hidden and when some one click on top button its visible and it wil be hidden when some one click outside this area 

And code for button mouse over is

    private void showTopMenu_MouseEnter(object sender, MouseEventArgs e)     {                   TopMenuArea.Visibility = Visibility.Visible;     } 

How can i apply a animation effect while changing the visibility of TopMenuArea ? Is any way to do it from xaml directly?

回答1:

Eventtrigger

 

Or use a style for fade in and out (with mouse enter / exit eventhandler like you did it)

Just define the style in your App Resources, or in the local Window or UserControl. You reuse the Animation style for any control.

use this in your Stackpanel

 


回答2:

It's an old question, but I've put together an open source library to allow fading and/or translation on Visibility changed, Loaded or binding.

You can find it at SciChart.Wpf.UI.Transitionz on Github and on NuGet.

Usage:

Which results in:



回答3:

here is a sample example

      some controls here in a horizontal strip , by default its hidden and when some one click on top button its visible and it wil be hidden when some one click outside this area

in the sample above I have set IsHitTestVisible="False" on the TopMenuArea dockPanel, as i can see that it is on top of previous (source for trigger panel)

other option is to use the TopMenuArea as the source if it is on the top

sample

      some controls here in a horizontal strip , by default its hidden and when some one click on top button its visible and it wil be hidden when some one click outside this area

give it a try and see if it is close to what you are looking for.

both of above just switch the opacity between 0 & 1, you may also use animation to make a fade effect if needed.



回答4:

You can use ToggleButton Checked and UnChecked Routed Event with Event Trigger:

 

Result:



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!