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 ...
随机推荐
- Yii系列教程(二):功能简介
1 MVC架构 1.1处理流程 一个Web请求在Yii内部的执行流程如下图所示: 1.2组件角色 组件名 角色与责任 index.php 入口脚本.创建Application的单例对象. applic ...
- Java 设计模式学习总结(上)
在编写和维护公司的现有代码的时候,我经常思考的问题是:怎样的系统算一个好的系统?如何设计具有扩展.可维护.复用的系统,它能最大限度的应对产品经理不断变化的需求.答案似乎是:设计模式. Remember ...
- hdu 1850 Being a Good Boy in Spring Festival(Nimm Game)
题意:Nimm Game 思路:Nimm Game #include<iostream> #include<stdio.h> using namespace std; int ...
- bjfu1287字符串输出的大水题
不多说 /* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> # ...
- Appium过程中用到的adb点滴知识库
一.认识abd adb是什么? adb的全称为Android Debug Bridge,就是起到调试桥的作用.通过adb我们可以在Eclipse中方面通过DDMS来调试Android程序,说白了就是d ...
- Linux环境Weblogic10g服务部署
1.先安装XManager: 2.进入XShell,远程连接Linux主机后,按如下操作即可打开XManager配置WebLogic部署服务: [root@server36 bin]# cd /[ro ...
- MFC类目录及头文件(转)
类 描述 头文件 CAnimateCtrl 自动化通用控件 afxcmn.h CArchive afx.h CArchiveException afx.h CArray afxtempl.h CAsy ...
- stringstream实例
stringstream的具体作用稍后来总结,这里分享一个实例,从txt文档中读取数据,并对进行处理. #include <iostream> #include <sstream&g ...
- XAML概览 1(译自JeremyBytes.com)
(文章译自JeremyBytes.com,由于原文太长,故分成几篇,能力所限,如有疏漏,希望海涵.另外若有侵权,务必尽快告知) Overview 了解XAML (可扩展应用程序标记语言)是使用WPF和 ...
- effective c++:private继承
如果class间使用private继承关系,编译器就不会自动的将派生类转换为基类,而且private继承而来的成员都变为private属性. private继承意味着根据某物实现出,当我们想要避免重复 ...