WPF自动隐藏的消息框(鼠标放上去将一直显示,移开动画继续),提供normal和error两种边框。
2016-07-11 16:46
513 查看
原地址-> /article/11898562.html
介绍:传统的确定,取消,OK,CANCAL之类的对话框太繁琐了,由于项目需要而诞生的仿手机式提示对话框。当然传统的对话框项目中也有,这里就不做介绍了。
出场和退场动画做得很简单,就用Blend随便鼓捣了一番,将就用吧。
预览效果如下:
View Code
注意:鼠标移动上去停止动画和移出后快速消失的代码为:
后台代码逻辑:
其中 :
其中ModelBase在 可分组的选择框控件(MVVM下)(Toggle样式 仿造单选框RadioButton,复选框CheckBox功能) 中有介绍。
最后,调用方法:
new OnlyShowMessageBox().Show("请注意:前方高能,禁止入内!", false);
或者
new OnlyShowMessageBox().Show("不存在此对象!", true);
介绍:传统的确定,取消,OK,CANCAL之类的对话框太繁琐了,由于项目需要而诞生的仿手机式提示对话框。当然传统的对话框项目中也有,这里就不做介绍了。
出场和退场动画做得很简单,就用Blend随便鼓捣了一番,将就用吧。
预览效果如下:
<Storyboard x:Key="ShowSb" Completed="Storyboard_Completed"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="grid1"> <EasingDoubleKeyFrame KeyTime="0" Value="{Binding YOffSet}"/> <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/> <EasingDoubleKeyFrame KeyTime="0:0:3" Value="0"/> <EasingDoubleKeyFrame KeyTime="0:0:3.5" Value="{Binding YOffSet}"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="grid2"> <EasingDoubleKeyFrame KeyTime="0" Value="{Binding YOffSet}"/> <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/> <EasingDoubleKeyFrame KeyTime="0:0:3" Value="0"/> <EasingDoubleKeyFrame KeyTime="0:0:3.5" Value="{Binding YOffSet}"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="tb"> <EasingDoubleKeyFrame KeyTime="0" Value="{Binding YOffSet}"/> <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/> <EasingDoubleKeyFrame KeyTime="0:0:3" Value="0"/> <EasingDoubleKeyFrame KeyTime="0:0:3.5" Value="{Binding YOffSet}"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="MouseLeave" Completed="Storyboard_Completed"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid1"> <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid2"> <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="tb"> <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="grid1"> <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="{Binding YOffSet}"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="grid2"> <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="{Binding YOffSet}"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="tb"> <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="{Binding YOffSet}"/> </DoubleAnimationUsingKeyFrames> </Storyboard>
View Code
注意:鼠标移动上去停止动画和移出后快速消失的代码为:
<i:Interaction.Triggers> <i:EventTrigger EventName="MouseEnter"> <ei:ControlStoryboardAction Storyboard="{StaticResource ShowSb}" ControlStoryboardOption="Stop"/> </i:EventTrigger> <i:EventTrigger EventName="MouseLeave"> <ei:ControlStoryboardAction Storyboard="{StaticResource MouseLeave}"/> </i:EventTrigger> </i:Interaction.Triggers>
后台代码逻辑:
private bool iserror = false; public void Show(string messageBoxText, bool iserror = false) { this.iserror = iserror; this.Message = messageBoxText; this.Show(); } public OnlyShowMessageBox() { InitializeComponent(); this.DataContext = new model() { YOffSet = -300d }; this.Loaded += (y, k) => { this.Top = 41; this.Left = (SystemParameters.WorkArea.Width) / 2 - this.ActualWidth / 2; if (iserror) { this.grid1.Visibility = Visibility.Collapsed; } else { this.grid2.Visibility = Visibility.Collapsed; } (this.Resources["ShowSb"] as Storyboard).Begin(); }; } private void Storyboard_Completed(object sender, EventArgs e) { this.Close(); }
其中 :
public class model : ModelBase { private double YOffset; public double YOffSet { get { return YOffset; } set { YOffset = value; RaisePropertyChangedEvent("YOffSet"); } } }
其中ModelBase在 可分组的选择框控件(MVVM下)(Toggle样式 仿造单选框RadioButton,复选框CheckBox功能) 中有介绍。
最后,调用方法:
new OnlyShowMessageBox().Show("请注意:前方高能,禁止入内!", false);
或者
new OnlyShowMessageBox().Show("不存在此对象!", true);
相关文章推荐
- flask test_client设置cookies
- (4.2.33.1)Android上玩玩Hook(2):Cydia Substrate演练
- 关于UILabel
- levelDB源码学习——Arena(简单内存池)
- c 快速排序
- java调用R语言实现神经网络
- redis的pipeline测试分析
- 反省与规划
- IE支持rgba半透明的方法
- jquery.chosen.js实现模糊搜索
- 服务器缓存帮助类
- java TCP socket编程1
- Android进阶之WebView使用与兼容4.+滑动到顶部
- python脚本――一种连接mysql数据库的方法(取回数据为list非tuple格式)并将数据写入TXT
- AMD规范
- Ubuntu 把Tomcat8 设置成系统服务
- 关于UIButton
- 关于下载JDK及配置环境变量一些细节
- python opencv(6)生成负片和水印
- mysql事件