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 三个视图,主视图能够左右滑动.实现抽屉效 ...
随机推荐
- webuploader 小demo
页面写法 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- 初步安装git使用命令配置电脑中的git关联的账户
原文地址 https://www.jianshu.com/p/39684a3ad4fa 出现问题 当我们初步使用git的时候,会报一些出乎预料的错误,比如:报错:fatal: unable to au ...
- [Angular] Test component template
Component: import { Component, Input, ChangeDetectionStrategy, EventEmitter, Output } from '@angular ...
- Lucene学习总结之七:Lucene搜索过程解析 2014-06-25 14:23 863人阅读 评论(1) 收藏
一.Lucene搜索过程总论 搜索的过程总的来说就是将词典及倒排表信息从索引中读出来,根据用户输入的查询语句合并倒排表,得到结果文档集并对文档进行打分的过程. 其可用如下图示: 总共包括以下几个过程: ...
- 从程序员的角度分析微信小程序(编程语言:用到什么学什么)
从程序员的角度分析微信小程序(编程语言:用到什么学什么) 一.总结 一句话总结:微信小程序原理就是用JS调用底层native组件,和React Native非常类似.(需要时,用到时再学) 1.选择语 ...
- 在线生成 QR Code
http://tool.oschina.net/qr 在线生成二维码(QR码)-采用ZXing与d-project
- Android—— ubuntu下【CTS】測试TV真机
近期接触到CTS,据传不懂CTS就不算一个合格的android开发者,我之前一直没见周边谁用过.作为一个产品开发的android人员,我还是太年轻- 撰写不易,转载请注明出处:http://blog. ...
- JVM 调优 —— OutOfMemory
零. 简单介绍 OutOfMemory 意思就是须要申请更大的内存, 可是内存限制无法申请到须要的内存. 一. 解决方法 基本上解决方向有两种: 检查程序是否有问题. 是不是写死循环不停地创建并持有对 ...
- html5-4 HTML5超链接、URL地址和表格
html5-4 HTML5超链接.URL地址和表格 一.总结 一句话总结: 1.cellspace有什么用? 清除表格的单元格间距 26 <table border='1px' cellspac ...
- 第二篇:_UICascadingTextStorage attributesAtIndex:effectiveRange:]: Range or index out of bounds
注意下文标红字段: #pragma mark- 输入改变时 - (void) textFieldDidChanged:(UITextField *) TextField{ //搜索关键字一旦改变,将重 ...