wp———图片切换效果
此篇文章主要是记录一下使用XamlReader加载动画时遇到的一些问题。
首先呢,把源码附上
<phone:PhoneApplicationPage
x:Class="PicChangedAnimation.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot 是包含所有页面内容的根网格-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Image x:Name="image" Stretch="Fill" Source="/Image/a.jpg" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<CompositeTransform/>
</Image.RenderTransform>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragCompleted="GestureListener_DragCompleted_1"/>
</toolkit:GestureService.GestureListener>
</Image>
<Image x:Name="image1" Stretch="Fill" Source="/Image/b.jpg" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<CompositeTransform/>
</Image.RenderTransform>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragCompleted="GestureListener_DragCompleted_2"/>
</toolkit:GestureService.GestureListener>
</Image>
</Grid> </phone:PhoneApplicationPage>
using System;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Controls;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;
using System.Windows.Media.Animation; namespace PicChangedAnimation
{
public partial class MainPage : PhoneApplicationPage
{
// 构造函数
public MainPage()
{
InitializeComponent();
} // ====================================================================================================================
private void GestureListener_DragCompleted_1(object sender, DragCompletedGestureEventArgs e) {
if (e.HorizontalChange < - && e.HorizontalVelocity < ) {
//LeftSlideStoryboard.Begin();
string moveLeft = -(LayoutRoot.ActualWidth) + "";
Storyboard sb = InitLeftSlideStoryboard(moveLeft, image1, image);
if (sb != null) {
try {
sb.Begin();
} catch (Exception ex) {
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
e.Handled = true;
} else if (e.HorizontalChange > && e.HorizontalVelocity > ) {
string moveLeft = LayoutRoot.ActualWidth + "";
Storyboard sb = InitLeftSlideStoryboard(moveLeft, image1, image);
if (sb != null) {
try {
sb.Begin();
} catch (Exception ex) {
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
e.Handled = true;
}
} private void GestureListener_DragCompleted_2(object sender, DragCompletedGestureEventArgs e) {
if (e.HorizontalChange < - && e.HorizontalVelocity < ) {
//LeftSlideStoryboard.Begin();
string moveLeft = -(LayoutRoot.ActualWidth) + "";
Storyboard sb = InitLeftSlideStoryboard(moveLeft, image, image1);
if (sb != null) {
try {
sb.Begin();
} catch (Exception ex) {
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
e.Handled = true;
} else if (e.HorizontalChange > && e.HorizontalVelocity > ) {
string moveLeft = LayoutRoot.ActualWidth + "";
Storyboard sb = InitLeftSlideStoryboard(moveLeft, image, image1);
if (sb != null) {
try {
sb.Begin();
} catch (Exception ex) {
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
e.Handled = true;
}
} // ====================================================================================================================
// // {0}-{-480}
// private string LEFT_SLIDE_STORYBOARD =
// @"<Storyboard x:Name=""LeftSlideStoryboard""
// xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
// xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
// xmlns:phone=""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone""
// xmlns:shell=""clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone""
// xmlns:d=""http://schemas.microsoft.com/expression/blend/2008""
// xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006""
// mc:Ignorable=""d"" >
// <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=""(UIElement.Opacity)"">
// <EasingDoubleKeyFrame KeyTime=""0"" Value=""0""/>
// <EasingDoubleKeyFrame KeyTime=""0:0:0.6"" Value=""1""/>
// </DoubleAnimationUsingKeyFrames>
// <DoubleAnimation Duration=""0:0:0.6"" To=""0"" Storyboard.TargetProperty=""(UIElement.Opacity)"" d:IsOptimized=""True""/>
// <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=""(UIElement.RenderTransform).(CompositeTransform.TranslateX)"">
// <EasingDoubleKeyFrame KeyTime=""0:0:0.6"" Value=""{0}""/>
// <EasingDoubleKeyFrame KeyTime=""0:0:0.61"" Value=""0""/>
// </DoubleAnimationUsingKeyFrames>
// </Storyboard>";
private string LEFT_SLIDE_STORYBOARD =
@"<Storyboard x:Name=""LeftSlideStoryboard""
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:phone=""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone""
xmlns:shell=""clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone""
xmlns:d=""http://schemas.microsoft.com/expression/blend/2008""
xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006""
mc:Ignorable=""d"" >
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=""(UIElement.Opacity)"">
<EasingDoubleKeyFrame KeyTime=""0"" Value=""0""/>
<EasingDoubleKeyFrame KeyTime=""0:0:0.01"" Value=""0""/>
<EasingDoubleKeyFrame KeyTime=""0:0:0.6"" Value=""1""/>
<EasingDoubleKeyFrame KeyTime=""0:0:0.61"" Value=""1""/>
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty=""(UIElement.Visibility)"">
<DiscreteObjectKeyFrame KeyTime=""0"">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime=""0:0:0.01"">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime=""0:0:0.6"">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime=""0:0:0.61"">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=""(UIElement.Opacity)"">
<EasingDoubleKeyFrame KeyTime=""0"" Value=""1""/>
<EasingDoubleKeyFrame KeyTime=""0:0:0.01"" Value=""1""/>
<EasingDoubleKeyFrame KeyTime=""0:0:0.6"" Value=""0""/>
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty=""(UIElement.Visibility)"">
<DiscreteObjectKeyFrame KeyTime=""0"">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime=""0:0:0.01"">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime=""0:0:0.6"">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime=""0:0:0.61"">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=""(UIElement.RenderTransform).(CompositeTransform.TranslateX)"">
<EasingDoubleKeyFrame KeyTime=""0:0:0.6"" Value=""{0}""/>
<EasingDoubleKeyFrame KeyTime=""0:0:0.61"" Value=""0""/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>"; public Storyboard InitLeftSlideStoryboard(string moveLeft, Image backCtrl, Image frontCtrl) {
string displayXaml = string.Format(LEFT_SLIDE_STORYBOARD, moveLeft);
Storyboard storyboard = null;
try {
storyboard = XamlReader.Load(displayXaml) as Storyboard;
Storyboard.SetTarget(storyboard.Children[], backCtrl);
Storyboard.SetTarget(storyboard.Children[], backCtrl);
Storyboard.SetTarget(storyboard.Children[], frontCtrl);
Storyboard.SetTarget(storyboard.Children[], frontCtrl);
Storyboard.SetTarget(storyboard.Children[], frontCtrl);
} catch (Exception e) {
System.Diagnostics.Debug.WriteLine(e.Message);
}
return storyboard;
} }
}
然后呢,说下遇到的问题:
1、“System.Windows.Markup.XamlParseException”类型的第一次机会异常在 System.Windows.ni.dll 中发生undeclared prefix [Line: 1 Position: 42]
问题出在,加载xaml语句时,存在没有声明就使用的类型前缀
我们添加上下面的引用就可以了
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:phone=""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone""
xmlns:shell=""clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone""
xmlns:d=""http://schemas.microsoft.com/expression/blend/2008""
xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006""
mc:Ignorable=""d""
2、“System.InvalidOperationException”类型的第一次机会异常在 System.Windows.ni.dll 中发生Animation target not specified.
问题出在,没有指定动画的目标控件,但即使我们在xaml中指定了,但一样会出现这样的问题,原因在上面的xaml中没有控件的声明。
解决方法可以采用c#代码中指定,如下
storyboard = XamlReader.Load(displayXaml) as Storyboard;
Storyboard.SetTarget(storyboard.Children[], backCtrl);
Storyboard.SetTarget(storyboard.Children[], backCtrl);
Storyboard.SetTarget(storyboard.Children[], frontCtrl);
Storyboard.SetTarget(storyboard.Children[], frontCtrl);
Storyboard.SetTarget(storyboard.Children[], frontCtrl);
wp———图片切换效果的更多相关文章
- js鼠标滚轮滚动图片切换效果
效果体验网址:http://keleyi.com/keleyi/phtml/image/12.htm HTML文件代码: <!DOCTYPE html PUBLIC "-//W3C// ...
- 精致3D图片切换效果,最适合企业产品展示
这是一个精致的立体图片切换效果,特别适合企业产品展示,可立即用于实际项目中.支持导航和自动播放功能, 基于 CSS3 实现,推荐使用最新的 Chrome,Firefox 和 Safari 浏览器浏览效 ...
- jquery简单的图片切换效果,支持pc端、移动端的banner图片切换开发
详细内容请点击 无意中看见了两年前写的一个图片切换,那会儿刚刚学习网页制作,可以说是我的第一个处女座的jquery图片切换效果.无聊之余对它的宽度稍稍做了一下修改,变成了支持pc端.手机端全屏的ban ...
- 100种不同图片切换效果插件pageSwitch
分享100种不同图片切换效果插件pageSwitch.这是一款适用于全屏切换场景,即一切一屏,并且实现了超过一百种切换效果,支持自定义切页动画.效果图如下: 在线预览 源码下载 实现的代码. ht ...
- Flash 用FLASH遮罩效果做图片切换效果
本教程是关于FLASH应用遮罩效果制作好看的图片切换效果.该教程选用FLASH遮罩中最简单的一种作为例子,当然你可以用自己的想象力来做出更多更好的图片动画.希望本教程能带你带来帮助. 让我们先看看效果 ...
- 10款好用的 jQuery 图片切换效果插件
jQuery 是一个非常优秀的 Javascript 框架,使用简单灵活,同时还有许多成熟的插件可供选择.其中,最令人印象深刻的应用之一就是对图片的处理,它可以让帮助你在你的项目中加入一些让人惊叹的效 ...
- js原生带缩略图的图片切换效果
js原生带缩略图的图片切换效果 本例中用到的 moveElement(elementID,final_x,final_y,interval)是来自<JavaScript DOM编程艺术(中文第二 ...
- jquery带按钮的图片切换效果
<!doctype html> <html> <head> <meta charset="gb2312"> <title> ...
- javascript马赛克遮罩图片切换效果:XMosaic.js(转)
新鲜出炉的javascript图片切换特效,实现的是马赛克遮罩切换.在flash里,好实现遮罩动画很简单,不过JS实现起来就有些困难了. XMosaic.js,与XScroll.js和XScroll2 ...
随机推荐
- js中关于arguments
- 微信公众平台开发localStorage数据总是被清空
我把现在项目中的用户数据存储过程改成本地的,只用localStorage,但是随之而来很多问题,原因就是localStorage只有很短的有效时间,退出公众号,关闭微信都会清空.最不能容忍的是用户还在 ...
- Drupal配置文件settings.php搜索规则
Drupal的配置文件搜索是通过bootstrap.inc的conf_path()函数实现的: function conf_path($require_settings = TRUE, $reset ...
- ASP.NET 使用application和session对象写的简单聊天室程序
ASP.Net中有两个重要的对象,一个是application对象,一个是session对象. Application:记录应用程序参数的对象,该对象用于共享应用程序级信息. Session:记录浏览 ...
- echo输出空行
rem 以下方法都可以输出空行,这十种方法分为三组,每组的效率依次递减 echo= echo, echo; echo+ echo/ echo[ echo] echo: echo. echo\
- 七牛云实现js上传
七牛云的官方API写的一塌糊涂.最主要的,还是版本兼容的问题. 一.引入文件 引入了两个文件: 1.jquery-1.10.2.min.js 2.plupload.full.min.js 3.qini ...
- linux系统中内存爆满之后会如何?
在使用python写程序的时候,发现一个可以无限迭代的迭代器,从而可以直接将系统中的内存占满,那么占满之后会发生什么呢? 1. 创建无限迭代,生成列表,如下: [root@python ~]# pyt ...
- 【转】GUID学习
概念 GUID: 即Globally Unique Identifier(全球唯一标识符) 也称作 UUID(Universally Unique IDentifier) . GUID是一个通过特定算 ...
- 基于MapReduce的关系代数运算(2)
1.自然连接 Map函数:对于R中的每个元组(a,b),生成键值对(b,(R,a)),对于S中的每个元组(b,c),生成键值对(b,(S,c)) Reduce函数:每个键值b会与一系列对相关联,这些对 ...
- leetcode@ [273] Integer to English Words (String & Math)
https://leetcode.com/problems/integer-to-english-words/ Convert a non-negative integer to its englis ...