WPF实现抽屉效果
原文:WPF实现抽屉效果
界面代码(xaml):
<Window x:Class="TransAnimation.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid HorizontalAlignment="Center" Width="90" Height="130" Background="Blue" Margin="209,12,204,170"></Grid>
<Button Content="Button" HorizontalAlignment="Left" Margin="374.409,97,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
<StackPanel Height="265" HorizontalAlignment="Left" Margin="128,24,0,0" Name="Thumb1" VerticalAlignment="Top" Width="49" CanVerticallyScroll="False">
<StackPanel.RenderTransform>
<TranslateTransform x:Name="spt1"></TranslateTransform>
</StackPanel.RenderTransform>
<StackPanel.Clip>
<RectangleGeometry x:Name="spc1"></RectangleGeometry>
</StackPanel.Clip>
<Button Content="Button" Height="65" Name="button1" Width="40" />
<Button Content="Button" Height="65" Name="button2" Width="36" />
</StackPanel>
<Image Name="Thumb" Source="high.png" Width="90" Height="125" Margin="330,138,82,48">
<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>
</Window>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TransAnimation
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private bool _Expand = true;
public MainWindow()
{
InitializeComponent();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Expand = !_Expand;
}
public bool Expand
{
get { return _Expand; }
set
{
_Expand = value;
Duration duration = new Duration(TimeSpan.FromSeconds(2));
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 = 40; //收缩的大小
if (_Expand) // Expand
{
translateAnim.From = -delta;
translateAnim.To = 0;
clipAnim.From = new Rect(delta, 0, Thumb1.ActualWidth, Thumb1.ActualHeight);
clipAnim.To = new Rect(0, 0, Thumb1.ActualWidth, Thumb1.ActualHeight);
}
else //Shrink
{
translateAnim.From = 0;
translateAnim.To = -delta;
clipAnim.From = new Rect(0, 0, Thumb1.ActualWidth, Thumb1.ActualHeight);
clipAnim.To = new Rect(delta, 0, Thumb1.ActualWidth, Thumb1.ActualHeight);
}
spt1.BeginAnimation(TranslateTransform.XProperty, translateAnim);
spc1.BeginAnimation(RectangleGeometry.RectProperty, clipAnim);
}
}
}
}
WPF实现抽屉效果的更多相关文章
- Wpf 抽屉效果
在android开发中有抽屉效果,就是在页面的边上有一个按钮,可以通过点击或者拖拽这个按钮,让页面显示.Wpf也可以实现相同的效果. 主要是通过一个DoubleAnimation和RectAnimat ...
- C# WPF抽屉效果实现(C# WPF Material Design UI: Navigation Drawer & PopUp Menu)
时间如流水,只能流去不流回! 点赞再看,养成习惯,这是您给我创作的动力! 本文 Dotnet9 https://dotnet9.com 已收录,站长乐于分享dotnet相关技术,比如Winform.W ...
- 浅谈DrawerLayout(抽屉效果)
DrawerLayout是V4包下提供的一种左滑右滑抽屉布局效果. 实现效果如下: 因为是官方提供的,所以使用起来也相对的比较简单. DrawerLayout 提供 1.当界面弹出的时候,主要内容区会 ...
- iOS开发之抽屉效果实现
说道抽屉效果在iOS中比较有名的第三方类库就是PPRevealSideViewController.一说到第三方类库就自然而然的想到我们的CocoaPods,今天的博客中用CocoaPods引入PPR ...
- Android 抽屉效果的导航菜单实现
Android 抽屉效果的导航菜单实现 抽屉效果的导航菜单 看了很多应用,觉得这种侧滑的抽屉效果的菜单很好. 不用切换到另一个页面,也不用去按菜单的硬件按钮,直接在界面上一个按钮点击,菜单就滑出来,而 ...
- 对抽屉效果几大github第三方库的调研
在公司项目新版本方案选择中,对主导航中要使用的抽屉效果进行了调研.主要原因是旧的项目中所用的库ECS评价不是很好.现对当下比较火的几大热门抽屉效果的第三方库进行了调研.代码全部选自github 如果你 ...
- ios开发中超简单抽屉效果(MMDrawerController)的实现
ios开发中,展示类应用通常要用到抽屉效果,由于项目需要,本人找到一个demo,缩减掉一些不常用的功能,整理出一个较短的实例. 首先需要给工程添加第三方类库 MMDrawerController: 这 ...
- iOS开发——实用技术OC篇&简单抽屉效果的实现
简单抽屉效果的实现 就目前大部分App来说基本上都有关于抽屉效果的实现,比如QQ/微信等.所以,今天我们就来简单的实现一下.当然如果你想你的效果更好或者是封装成一个到哪里都能用的工具类,那就还需要下一 ...
- 玩转iOS开发 - 简易的实现2种抽屉效果
BeautyDrawer BeautyDrawer 是一款简单易用的抽屉效果实现框架,集成的属性能够对view 滑动缩放进行控制. Main features 三个视图,主视图能够左右滑动.实现抽屉效 ...
随机推荐
- [Angular] @ContentChild with Directive ref
For example you have a component, which take a trasclude input element: <au-fa-input id="pas ...
- php面试题二--解决网站大流量高并发方案(从url到硬盘来解决高并发方案总结)
php面试题二--解决网站大流量高并发方案(从url到硬盘来解决高并发方案总结) 一.总结 从外到内解决网站大流量高并发问题---从提交一个url开始(从用户按下搜索栏回车键开始) url最开始会到d ...
- MouseGestureLahk
http://cyber-furoshiki.com/win-mouse-gesture-l http://www.vector.co.jp/download/file/winnt/util/fh68 ...
- 微信测试号开发之四 获取access_token和jsapi_ticket
原文:https://blog.csdn.net/qq_37936542/article/details/78549233 access_token:公众号的全局唯一接口调用凭据,公众号调用各接口时都 ...
- Java NIO学习笔记之基本概念
一.缓冲区操作 缓冲区,以及缓冲区如何工作,是所有 I/O 的基础.所谓"输入/输出"讲的无非就是把数据移进或移出缓冲区. 进程使用 read( )系统调用,要求其缓冲区被填满.内 ...
- html5-8 如何控制html5中的视频标签和音频标签
html5-8 如何控制html5中的视频标签和音频标签 一.总结 一句话总结:找到视频或者音频的element对象,然后查手册看对应的方法或者属性就可以,里面有控制的. 1.如何控制html5中的视 ...
- php自定义排序数组usort和uasort(uasort保持索引关联)(usort($arr, "cmp");)(比较函数时很普通函数的写法:function cmp($a, $b))
php自定义排序数组usort和uasort(uasort保持索引关联)(usort($arr, "cmp");)(比较函数时很普通函数的写法:function cmp($a, $ ...
- Android应用程序文件缓存getCacheDir()和getExternalCacheDir()
如果Android引用程序需要缓存临时文件,系统提供了一个可管理的“内部缓存”和一个不可管理的“外部缓存”,分别调用getCacheDir()和getExternalCacheDir()方法,可以从当 ...
- Python爬虫突破封禁的6种常见方法
转 Python爬虫突破封禁的6种常见方法 2016年08月17日 22:36:59 阅读数:37936 在互联网上进行自动数据采集(抓取)这件事和互联网存在的时间差不多一样长.今天大众好像更倾向于用 ...
- Indy10 控件的使用(2)TidTCpServer组件学习
以下来自英文原版帮助文件,文桓英语不好,翻译了老半天.有错误的地方见谅,别骂我. TIdTCPServer = class(TIdComponent) Description TIdTCPServer ...