Silverlight带关闭动画的内容控件,可移动的内容控件(一)
本例给大家介绍两个自定义控件,一个有显示和关闭两种状态,在状态切换时有动画效果。另外一个是可以拖动的内容控件,可以制作能拖动的面板。
A.带关闭动画的内容控件。
.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:SuperMapStandardMapApp1"><Style TargetType="local:CustomPanel"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="local:CustomPanel"><Grid x:Name="LayoutRoot" RenderTransformOrigin="{TemplateBinding RenderTransformOrigin}"><VisualStateManager.VisualStateGroups><VisualStateGroup x:Name="ViewStates"><VisualState x:Name="Open"><Storyboard><DoubleAnimation BeginTime="00:00:00" Duration="00:00:0.3" Storyboard.TargetName="CustomPanelScale" Storyboard.TargetProperty="ScaleY" To="1" /><DoubleAnimation BeginTime="00:00:00" Duration="00:00:0.3" Storyboard.TargetName="CustomPanelScale" Storyboard.TargetProperty="ScaleX" To="1" /><DoubleAnimation BeginTime="00:00:00" Duration="00:00:0.3" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="Opacity" To="1" /></Storyboard></VisualState><VisualState x:Name="Close"><Storyboard><DoubleAnimation BeginTime="00:00:00" Duration="00:00:0.2" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="Opacity" To="0" /><DoubleAnimation BeginTime="00:00:00" Duration="00:00:0.2" Storyboard.TargetName="CustomPanelScale" Storyboard.TargetProperty="ScaleY" To="0" /><DoubleAnimation BeginTime="00:00:00" Duration="00:00:0.2" Storyboard.TargetName="CustomPanelScale" Storyboard.TargetProperty="ScaleX" To="1" /></Storyboard></VisualState></VisualStateGroup></VisualStateManager.VisualStateGroups><ContentPresenter x:Name="Content" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"></ContentPresenter><Grid.RenderTransform><ScaleTransform x:Name="CustomPanelScale" ScaleX="1" ScaleY="1" /></Grid.RenderTransform></Grid></ControlTemplate></Setter.Value></Setter><Setter Property="Foreground" Value="Red"/></Style> </ResourceDictionary>
定义两 VisualState 一个open,一个close 代表内容控件的两个状态,添加ContentPresenter标签代表内容控件所添加的内容。
.cs
namespace SuperMapStandardMapApp1{ [TemplateVisualState(GroupName = "ViewStates", Name = "Open")] [TemplateVisualState(GroupName = "ViewStates", Name = "Close")]public partial class CustomPanel : ContentControl {public CustomPanel() { DefaultStyleKey = typeof(CustomPanel); } public override void OnApplyTemplate() {base.OnApplyTemplate();this.ChangeVisualState(true); } #region Dependency Properties /// <summary>/// 获取或设置内容控件是否显示/// </summary>/// <value>/// <c>true</c> 设置时控件进行显示; 否则不显示, <c>false</c>./// </value>/// public bool IsOpnen {get { return (bool)GetValue(IsOpenProperty); }set { SetValue(IsOpenProperty, value); } } public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register("IsOpen", typeof(bool), typeof(CustomPanel), new PropertyMetadata(true, OnIsOpenPertyChange)); public static void OnIsOpenPertyChange(DependencyObject obj, DependencyPropertyChangedEventArgs e) { (obj as CustomPanel).ChangeVisualState(true); } #endregion private void ChangeVisualState(bool useTransitions) {if (IsOpnen) { VisualStateManager.GoToState(this, "Open", useTransitions); }else { VisualStateManager.GoToState(this, "Close", useTransitions); } } }}
说明两个:TemplateVisualState分别代表close和open状态,注册一个DependencyProperty ISOpen表示此内容面板是否开启,在ChangeVisualState方法中,通过 VisualStateManager.GoToState(this, "Open", useTransitions); VisualStateManager.GoToState(this, "Close", useTransitions);说明转化到哪个状态。这样便定义了一个可以有两状态相互转化的内容控件!如图:
转载于:https://www.cnblogs.com/doudougou/archive/2011/08/14/2138491.html
Silverlight带关闭动画的内容控件,可移动的内容控件(一)相关推荐
- 【Silverlight】Bing Maps开发应用与技巧二:自定义图钉标注控件和动态ToolPanel
在Bing Maps Silverlight Control中以及为我们提供了地图图钉控件Pushpin,我曾经在< 使用图钉层(Pushpin layer)及地图图层(MapLayer)> ...
- WPF Thumb、控件、窗体、内容、Shape拖动
实例地址:WPFThumb.控件.窗体.内容拖动实例-C#文档类资源-CSDN下载 WPF常见拖动方式: 1.窗体拖动:使用窗体自带拖动方法,DragMove(). 2.Thumb控件拖动:WPF拖动 ...
- WPF编程,将控件所呈现的内容保存成图像的一种方法。
WPF编程,将控件所呈现的内容保存成图像的一种方法. 原文:WPF编程,将控件所呈现的内容保存成图像的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.ne ...
- android基础 [超级详细android常用控件解析(ScollView控件,ProgressBar进度条,PopupWindow控件)]
目录 1 章节目录 2 ScollView控件 2.1 ScrollView简介 2.2 ScrollView使用 2.3 常用属性及方法 3 ProgressBar进度条 3.1 简介 3.2 常用 ...
- silverlight,WPF动画终极攻略之白云飘,坐车去旅游篇(Blend 4开发)
原文:silverlight,WPF动画终极攻略之白云飘,坐车去旅游篇(Blend 4开发) 这章有点长,所以我分成了两章.这一章主要是准备工作,差不多算美工篇吧,这章基本不会介绍多少动画效果,主要讲 ...
- ESP32 开发笔记(四)LVGL控件学习 ColorPicker 颜色选择器控件
先看效果,创建一个颜色选择器控件,设置事件回调动态显示当前选择的颜色值 开发板购买链接https://item.taobao.com/item.htm?spm=a2oq0.12575281.0.0.5 ...
- Winform(C#) 国内开源美化控件主题库2:花木兰控件库
Winform(C#) 国内开源美化控件主题库2:花木兰控件库 地址 博客:https://www.cnblogs.com/tlmbem/控件的介绍. gitee:https://gitee.com/ ...
- java 用户控件_C#自定义控件VS用户控件
C#中自定义控件VS用户控件大比拼 1 自定义控件与用户控件区别 WinForm中, 用户控件(User Control):继承自 UserControl,主要用于开发 Container 控件,Co ...
- android按钮控件常见问题,Android的基本控件和Activity的应用总结
Android的基本控件 常用界面控件 TextView 显示文本信息 button 普通按钮 EditText 可编辑的文本框组件(输入框) ImageView 用于显示图片 ImageBUtton ...
最新文章
- Postman使用Date数据类型,Postman发送Date类型数据,Postman模拟前端调用
- 134个预训练模型、精度高达85.1%,百度视觉算法最强基石PaddleClas全新升级
- TiDB 在知乎万亿量级业务数据下的实践和挑战
- poj 1469 COURSES 解题报告
- java.nio.ByteBuffer用法小结
- C++11多线程------std::async
- mysql 直接删表空间文件_oracle删除(释放)数据文件/表空间流程
- linux 防火墙 80端口,Linux配置防火墙,开启80端口、3306端口
- CV经典入门教程:《计算机视觉:算法与应用》第二版
- vue-cli搭建项目引入jquery和jquery-weui步骤详解
- 智能驾驶的狂想与现实落地
- 【Python】使用python 画出一张机器猫doraemon
- 28张高清数据分析全知识地图,强烈建议收藏
- 黑苹果10.15.7安装comfast永存,CF-811AC驱动方法
- golang 生成二维码名片 海报
- 宋智孝那个机器人_陈柏霖机器人竟然冷落宋智孝
- 捋一捋Kafka中的消费者API
- 【BZOJ4484】【JSOI2015】最小表示(拓扑排序,bitset)
- 【规则】Adblock Plus 广告过滤规则自用整理
- Win10怎么删除快速访问中最近使用文件记录