Wpf 抽屉效果
2014-03-11 19:11
218 查看
在android开发中有抽屉效果,就是在页面的边上有一个按钮,可以通过点击或者拖拽这个按钮,让页面显示。Wpf也可以实现相同的效果。
主要是通过一个DoubleAnimation和RectAnimation动画实现
Demo地址
http://pan.baidu.com/s/1gdxHhnX
主要是通过一个DoubleAnimation和RectAnimation动画实现
<Grid HorizontalAlignment="Center" Width="90" Height="130" Background="Blue"> <Image x:Name="Thumb" Source="high.png" Width="90" Height="125"> <Image.RenderTransform> <TranslateTransform x:Name="Translate"></TranslateTransform> </Image.RenderTransform> <Image.Clip> <RectangleGeometry x:Name="ClipRect" Rect="0,0,90,125" ></RectangleGeometry> </Image.Clip> </Image> </Grid>
private bool _Expand = true; public bool Expand { get { return _Expand; } set { _Expand = value; Duration duration = new Duration(TimeSpan.FromSeconds(1)); FillBehavior behavior = FillBehavior.HoldEnd; DoubleAnimation translateAnim = new DoubleAnimation(); translateAnim.Duration = duration; translateAnim.FillBehavior = behavior; RectAnimation clipAnim = new RectAnimation(); clipAnim.Duration = duration; clipAnim.FillBehavior = behavior; double delta = 80; //收缩的大小 if (_Expand) // Expand { translateAnim.From = -delta; translateAnim.To = 0; clipAnim.From = new Rect(delta, 0, Thumb.ActualWidth, Thumb.ActualHeight); clipAnim.To = new Rect(0, 0, Thumb.ActualWidth, Thumb.ActualHeight); } else //Shrink { translateAnim.From = 0; translateAnim.To = -delta; clipAnim.From = new Rect(0, 0, Thumb.ActualWidth, Thumb.ActualHeight); clipAnim.To = new Rect(delta, 0, Thumb.ActualWidth, Thumb.ActualHeight); } Translate.BeginAnimation(TranslateTransform.XProperty, translateAnim); ClipRect.BeginAnimation(RectangleGeometry.RectProperty, clipAnim); } }
Demo地址
http://pan.baidu.com/s/1gdxHhnX
相关文章推荐
- Ubuntu启动错误Checking Battery State的处理
- UIViewController与UISplitViewController之间的切换
- linux 更新系统时间
- poj3468树状数组之区间更新+区间询问
- 【Leetcode】Remove Duplicates from Sorted List
- 十大OpenGL教程
- 黑马程序员 第3天 JAVA if和switch语句
- Java修改properties文件
- 【Kettle从零开始】实例下载
- ubuntu进程管理方法
- 分布式应用通信协议
- LeetCode Minimum Depth of Binary Tree
- JS常用的正则表达式总结
- Apache mod_wsgi部署Django项目
- BINARY SEARCH in read table statement
- Linux下chkconfig用法详解
- Nginx server之Nginx作为web服务器(基于域名或IP的web服务器)
- MVC中JQuery文件引入的路径问题,@Url.Content函数
- [问题2014S01] 解答
- html5的Input Attr : Autofocus,感觉挺有意思的!