Silverlight带关闭动画的内容控件,可移动的内容控件(一)

本例给大家介绍两个自定义控件,一个有显示和关闭两种状态,在状态切换时有动画效果。另外一个是可以拖动的内容控件,可以制作能拖动的面板。

         A.带关闭动画的内容控件。

  .xaml

ContractedBlock.gifExpandedBlockStart.gifView Code
<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

ContractedBlock.gifExpandedBlockStart.gifView Code
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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/475537.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

模型评价 - 判断数据模型拟合效果的三种方法

数据建模的目的就是获得从自变量映射到因变量的函数&#xff0c;在建模的探索过程中&#xff0c;不同的方式总会得出不同的函数模型&#xff0c;而这些函数大多是由一些参数构成的&#xff0c;比如 y f&#xff08; x; w0, w1, w2, w3, ...&#xff09;。 平方损失函数 为了选…

Autodesk云计算系列视频 --- 云计算与Civil 3D

前面的视频介绍了云计算与AutoCAD/Revit/Inventor的结合&#xff0c;这一节是云计算与Civil 3D的结合例子&#xff1a; 演示中使用的云计算程序源代码可以从下面链接下载&#xff1a; The sample code used in the demonstration is available here. 转载于:https://www.cnblo…

模型评价 - 机器学习与建模中怎么克服过拟合问题?

上一篇博客链接&#xff1a; 机器学习与建模中 - 判断数据模型拟合效果的三种方法 在上一篇博客中&#xff0c;我们谈到了使用损失函数来判断模型的拟合效果。但是拟合效果比较好的模型不一定是最好的模型&#xff0c;建模的最终目的是为了预测&#xff0c;因此预测最精准的模…

LeetCode 957. N 天后的牢房(查找循环节)

1. 题目 8 间牢房排成一排&#xff0c;每间牢房不是有人住就是空着。 每天&#xff0c;无论牢房是被占用或空置&#xff0c;都会根据以下规则进行更改&#xff1a; 如果一间牢房的两个相邻的房间都被占用或都是空的&#xff0c;那么该牢房就会被占用。 否则&#xff0c;它就…

获取数据 - 下载附件解压附件 - Python代码

一些线上化刚刚起步的部门&#xff0c;并不是所有的数据都是直接推送到服务器的数据库中&#xff0c;有些数据往往是数据中心通过邮件形式推送的&#xff0c;如果每天接收邮件--下载附件--解压--合并文件--导入数据库&#xff0c;对于数据工程师来说&#xff0c;这无疑是琐碎且…

技术标书的写法

1, 背景&#xff0c;用户对什么关心&#xff0c;就说什么。即使没有软件也可以&#xff0c;用画图软件先画出来。2&#xff0c;用户招标流程&#xff0c;弄到评分标准一切就OK 了&#xff0c;比如说什么时候该上台演示&#xff0c;如果没有评分标 准&#xff0c;站在评审角度…

LeetCode 947. 移除最多的同行或同列石头(并查集)

1. 题目 我们将石头放置在二维平面中的一些整数坐标点上。每个坐标点上最多只能有一块石头。 每次 move 操作都会移除一块所在行或者列上有其他石头存在的石头。 请你设计一个算法&#xff0c;计算最多能执行多少次 move 操作&#xff1f; 示例 1&#xff1a; 输入&#xf…

因子分析模型

主成分分析和因子分析 #包载入 library(corrplot) library(psych) library(GPArotation) library(nFactors) library(gplots) library(RColorBrewer)1234567 主成分分析 主成分分析&#xff08;PCA&#xff09;是对针对大量相关变量提取获得很少的一组不相关的变量&#xff…

网络机器人开发商

http://soft.pt42.com/blog_backup_index.htm转载于:https://www.cnblogs.com/carl2380/archive/2011/09/01/2162136.html

因子分析模型 - 案例按步骤详解 - (SPSS建模)

一、SPSS中的因子分析。 步骤: &#xff08;1&#xff09;定义变量&#xff1a;x1-财政用于农业的支出的比重,x2-第二、三产业从业人数占全社会从业人数的比重&#xff0c;x3-非农村人口比重&#xff0c;x4-乡村从业人员占农村人口的比重&#xff0c;x5-农业总产值占农林牧总…

MVC View 中 html 属性名与关键字冲突问题的分析与解决

在 MVC 的 View 中&#xff0c;允许使用 {} 来定义元素的属性。不过&#xff0c;HTML 中的 class 属性名与 C# 中的类 class 是冲突的&#xff0c;所以&#xff0c;在使用的时候&#xff0c;会发现不能使用 class 这个属性。解决的办法是在 class 前面加上一个 符号&#xff0…

神经网络 - 用单层感知器实现多个神经元的分类 - (Matlab建模)

训练样本矩阵&#xff1a; P [0.1 0.7 0.8 0.8 1.0 0.3 0.0 –0.3 –0.5 –1.5; 1.2 1.8 1.6 0.6 0.8 0.5 0.2 0.8 –1.5 –1.3]; 训练样本对应的分类&#xff1a; T [1 1 1 0 0 1 1 1 0 0 ;0 0 0 0 0 1 1 1 1 1]; 用MATLAB实现分类&…

LeetCode 1218. 最长定差子序列(哈希map)

1. 题目 给你一个整数数组 arr 和一个整数 difference&#xff0c;请你找出 arr 中所有相邻元素之间的差等于给定 difference 的等差子序列&#xff0c;并返回其中最长的等差子序列的长度。 示例 1&#xff1a; 输入&#xff1a;arr [1,2,3,4], difference 1 输出&#xff…

缺失值处理 - 定位空值并用空值的上一个值填充 - (Excel)

今天小助理很烦恼&#xff0c;说要处理一批汇率的数据&#xff0c;用近邻日期的汇率填充汇率为空的日期的汇率&#xff0c;这句话比较拗口&#xff0c;我们用数据解释一下。 比如下表&#xff0c;10月6日和10月8日9日的汇率没有采集到&#xff0c;那么我们就用10月5日的汇率填…

C#开发基础类库

下载地址&#xff1a;http://files.cnblogs.com/dashi/Sxmobi.rar转载于:https://www.cnblogs.com/dashi/archive/2011/09/09/2172506.html

LeetCode 1027. 最长等差数列(DP)

1. 题目 给定一个整数数组 A&#xff0c;返回 A 中最长等差子序列的长度。 回想一下&#xff0c;A 的子序列是列表 A[i_1], A[i_2], ..., A[i_k] 其中 0 < i_1 < i_2 < ... < i_k < A.length - 1。并且如果 B[i1] - B[i]( 0 < i < B.length - 1) 的值都…

因子分析模型 - 因子分析法原理与代码实现 -(Python,R)

因子分析基本思想 和主成分分析相似&#xff0c;首先从原理上说&#xff0c;主成分分析是试图寻找原有自变量的一个线性组合&#xff0c;取出对线性关系影响较大的原始数据&#xff0c;作为主要成分。 因子分析&#xff0c;是假设所有的自变量可以通过若干个因子&#xff08;中…

如何将两个DateTimePicker的日期和时间组合成一个值

有两个DateTimePicker&#xff0c;DateTimePicker1用于选择日期&#xff0c;DateTimePicker2用于选择Time&#xff0c;现在需要将两个DateTimePicker的值组合成一个DateTime使用。 方法&#xff1a; 1: DateTime dtTime Convert.ToDateTime(dateTimePicker1.Value.ToShortDate…

LeetCode 1255. 得分最高的单词集合(回溯)

1. 题目 你将会得到一份单词表 words&#xff0c;一个字母表 letters &#xff08;可能会有重复字母&#xff09;&#xff0c;以及每个字母对应的得分情况表 score。 请你帮忙计算玩家在单词拼写游戏中所能获得的「最高得分」&#xff1a;能够由 letters 里的字母拼写出的 任…

推荐几个网站 - (可视化、博客、社区、学习网站)

------------------------------------------------------------------------------------------------------------- 作者&#xff1a;Mf是个大坏蛋 原文&#xff1a;https://blog.csdn.net/destinymf/article/details/81186452 ----------------------------------------…