对于SilverlightValidationSummary不显示异常的小问题感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍silverlightplug-in没有响应,并为您提供关于ASP.
对于Silverlight ValidationSummary不显示异常的小问题感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍silverlight plug-in没有响应,并为您提供关于ASP.NET MVC Html.ValidationSummary(true) 不显示模型错误、asp.net MVC – ValidationSummary不显示、c# – Silverlight Programmatical Drawing(从Windows Forms转换为Silverlight)、Charlie Calvert: Silverlight Simple Animation的有用信息。
本文目录一览:- Silverlight ValidationSummary不显示异常的小问题(silverlight plug-in没有响应)
- ASP.NET MVC Html.ValidationSummary(true) 不显示模型错误
- asp.net MVC – ValidationSummary不显示
- c# – Silverlight Programmatical Drawing(从Windows Forms转换为Silverlight)
- Charlie Calvert: Silverlight Simple Animation
Silverlight ValidationSummary不显示异常的小问题(silverlight plug-in没有响应)
首先是错误的xaml代码
<Grid Name="gridProductDetails" Background="White" > <Grid.ColumnDeFinitions> <ColumnDeFinition Width="Auto"></ColumnDeFinition> <ColumnDeFinition></ColumnDeFinition> </Grid.ColumnDeFinitions> <Grid.RowDeFinitions> <RowDeFinition Height="Auto"></RowDeFinition> <RowDeFinition Height="Auto"></RowDeFinition> <RowDeFinition Height="Auto"></RowDeFinition> <RowDeFinition Height="Auto"></RowDeFinition> <RowDeFinition Height="*"></RowDeFinition> <RowDeFinition Height="Auto"></RowDeFinition> <RowDeFinition Height="Auto"></RowDeFinition> <RowDeFinition Height="Auto"></RowDeFinition> </Grid.RowDeFinitions> <TextBlock Margin="7">Model Number:</TextBlock> <TextBox Margin="5" Grid.Column="1" Width="100" HorizontalAlignment="Left" x:Name="txtModelNumber" Text="{Binding ModelNumber,Mode=TwoWay,ValidatesOnExceptions=True,NotifyOnValidationError=True}"></TextBox> <TextBlock Margin="7" Grid.Row="1">Model Name:</TextBlock> <TextBox Margin="5" Grid.Row="1" Grid.Column="1" Text="{Binding ModelName,TargetNullValue='[this is null]',NotifyOnValidationError=True}"></TextBox> <TextBlock Margin="7" Grid.Row="2">Unit Cost:</TextBlock> <TextBox Margin="5" Grid.Row="2" Grid.Column="1" x:Name="txtUnitCost" Width="100" HorizontalAlignment="Left" Text="{Binding UnitCost,Mode=TwoWay}"></TextBox> <TextBlock Margin="7,7,0" Grid.Row="3">Description:</TextBlock> <TextBox Margin="5" Grid.Row="3" Grid.Column="1" Text="{Binding ModelName2,FallbackValue='N/A load Failed'}"></TextBox> <TextBox Margin="7,9" Grid.Row="4" Grid.ColumnSpan="2" Text="{Binding Description,Mode=TwoWay}" textwrapping="Wrap"></TextBox> <StackPanel Margin="7" Grid.Row="5" Grid.ColumnSpan="2"> <TextBlock>汇总验证信息:</TextBlock> <sdk:ValidationSummary x:Name="validationSummary" MinHeight="50" /> <!--注意,必须将ValidationSummary放在Grid的下一级,不能在ValidationSummary和Grid间加上其他容器控件,否则不触发--> </StackPanel> <TextBlock Margin="7" Grid.Row="6" Grid.ColumnSpan="2" Foreground="Red" FontWeight="Bold" x:Name="lblInfo" ></TextBlock> <Button Grid.Row="7" x:Name="btnCheck" Click="btnCheck_Click">测试</Button> </Grid>
再是正确的xaml代码
<Grid Name="gridProductDetails" Background="White" > <Grid.ColumnDeFinitions> <ColumnDeFinition Width="Auto"></ColumnDeFinition> <ColumnDeFinition></ColumnDeFinition> </Grid.ColumnDeFinitions> <Grid.RowDeFinitions> <RowDeFinition Height="Auto"></RowDeFinition> <RowDeFinition Height="Auto"></RowDeFinition> <RowDeFinition Height="Auto"></RowDeFinition> <RowDeFinition Height="Auto"></RowDeFinition> <RowDeFinition Height="*"></RowDeFinition> <RowDeFinition Height="Auto"></RowDeFinition> <RowDeFinition Height="Auto"></RowDeFinition> <RowDeFinition Height="Auto"></RowDeFinition> </Grid.RowDeFinitions> <TextBlock Margin="7">Model Number:</TextBlock> <TextBox Margin="5" Grid.Column="1" Width="100" HorizontalAlignment="Left" x:Name="txtModelNumber" Text="{Binding ModelNumber,Mode=TwoWay}" textwrapping="Wrap"></TextBox> <sdk:ValidationSummary x:Name="validationSummary" MinHeight="50" Margin="7" Grid.Row="5" Grid.ColumnSpan="2"/> <!--注意,必须将ValidationSummary放在Grid的下一级,不能在ValidationSummary和Grid间加上其他容器控件,否则不触发--> <TextBlock Margin="7" Grid.Row="6" Grid.ColumnSpan="2" Foreground="Red" FontWeight="Bold" x:Name="lblInfo" ></TextBlock> <Button Grid.Row="7" x:Name="btnCheck" Click="btnCheck_Click">测试</Button> </Grid>
正确的后台代码
public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void UserControl_Loaded(object sender,RoutedEventArgs e) { //方式1,通过后台代码设置数据源 Product product = new Product("AEFS100","Portable",77,"Analyzes the electrical activity of a person's heart and applies " + "an electric shock if necessary."); gridProductDetails.DataContext = product; validationSummary.DataContext = product; } private void btnCheck_Click(object sender,RoutedEventArgs e) { Product product= gridProductDetails.DataContext as Product; lblInfo.Text = "Model Name: " + product.ModelName + "\nModel Number: " + product.ModelNumber + "\nUnit Cost: " + product.UnitCost; } }
public class Product { private string modelNumber; [StringLength(25)] [required(ErrorMessage="型号是必填字段")] public string ModelNumber { get { return modelNumber; } set { //if (value==null || string.IsNullOrEmpty(value.ToString())) //{ // throw new Exception("抛出异常,型号是必填字段"); //} ValidationContext context = new ValidationContext(this,null,null); context.MemberName = "ModelNumber"; Validator.ValidateProperty(value,context); modelNumber = value; } } private string modelName; [StringLength(26)] [required()] public string ModelName { get { return modelName; } set { ValidationContext context = new ValidationContext(this,null); context.MemberName = "ModelName"; Validator.ValidateProperty(value,context); modelName = value; } } private double unitCost; public double UnitCost { get { return unitCost; } set { unitCost = value; } } private string description; public string Description { get { return description; } set { description = value; } } public Product(string modelNumber,string modelName,double unitCost,string description) { ModelNumber = modelNumber; ModelName = modelName; UnitCost = unitCost; Description = description; } public Product() { } }
ASP.NET MVC Html.ValidationSummary(true) 不显示模型错误
我对 Html.ValidationSummary 有一些问题。我不想在 ValidationSummary 中显示属性错误。当我设置
Html.ValidationSummary(true) 时,它不会显示来自 ModelState 的错误消息。当控制器对字符串的操作出现异常时
MembersManager.RegisterMember(member);
catch 部分向 ModelState 添加了一个错误:
ModelState.AddModelError("error",ex.Message);
但 ValidationSummary 不显示此错误消息。当我设置 Html.ValidationSummary(false)
时,所有消息都会显示,但我不想显示属性错误。我该如何解决这个问题?
这是我正在使用的代码:
模型:
public class Member
{
[Required(ErrorMessage = "*")]
[DisplayName("Login:")]
public string Login { get; set; }
[Required(ErrorMessage = "*")]
[DataType(DataType.Password)]
[DisplayName("Password:")]
public string Password { get; set; }
[Required(ErrorMessage = "*")]
[DataType(DataType.Password)]
[DisplayName("Confirm Password:")]
public string ConfirmPassword { get; set; }
}
控制器:
[HttpPost]
public ActionResult Register(Member member)
{
try
{
if (!ModelState.IsValid)
return View();
MembersManager.RegisterMember(member);
}
catch (Exception ex)
{
ModelState.AddModelError("error",ex.Message);
return View(member);
}
}
看法:
<% using (Html.BeginForm("Register","Members",FormMethod.Post,new { enctype = "multipart/form-data" })) {%>
<p>
<%= Html.LabelFor(model => model.Login)%>
<%= Html.TextBoxFor(model => model.Login)%>
<%= Html.ValidationMessageFor(model => model.Login)%>
</p>
<p>
<%= Html.LabelFor(model => model.Password)%>
<%= Html.PasswordFor(model => model.Password)%>
<%= Html.ValidationMessageFor(model => model.Password)%>
</p>
<p>
<%= Html.LabelFor(model => model.ConfirmPassword)%>
<%= Html.PasswordFor(model => model.ConfirmPassword)%>
<%= Html.ValidationMessageFor(model => model.ConfirmPassword)%>
</p>
<div>
<input type="submit" value="Create" />
</div>
<%= Html.ValidationSummary(true)%>
<% } %>
asp.net MVC – ValidationSummary不显示
编辑:
ValidationSummary设置的断点显示:
ViewData.ModelState.Values[1].ErrorMessage = "" ViewData.ModelState.Values[1].Exception.InnerException.Message = "4a is not a valid value for Int32"
ValidationSummary是否使用ErrorMessage和ValidationMessage使用InnerException.Message?
我的查看代码是:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<App.Models.PurchaSEOrdersView>" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <title>Edit</title> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>Edit</h2> <%= Html.ValidationSummary() %> <% Html.BeginForm("Edit","PurchaSEOrder",FormMethod.Post); %> <table> <tr> <td> Purchase Order Id: </td> <td> <%= Html.TextBox("PurchaSEOrderId",Model.PurchaSEOrderId)%> <%= Html.ValidationMessage("PurchaSEOrderId")%> </td> </tr> <tr> <td> Date: </td> <td> <%= Html.TextBox("Date",Model.Date.ToString("dd-MMM-yyyy"))%> <%= Html.ValidationMessage("Date")%> </td> </tr> </table> <input type="submit" value="Save" /> <% Html.EndForm(); %> </asp:Content>
解决方法
string errorText = GetUserErrorMessageOrDefault(modelError,null /* modelState */);
请注意,对于modelState没有传递任何内容.现在与ValidationMessage对比:
... GetUserErrorMessageOrDefault(modelError,modelState) ...
最后,我们来看看GetUserErrorMessageOrDefault:
private static string GetUserErrorMessageOrDefault(ModelError error,ModelState modelState) { if (!String.IsNullOrEmpty(error.ErrorMessage)) { return error.ErrorMessage; } if (modelState == null) { return null; } string attemptedValue = (modelState.Value != null) ? modelState.Value.AttemptedValue : null; return String.Format(CultureInfo.CurrentCulture,MvcResources.Common_ValueNotValidForProperty,attemptedValue); }
这告诉我们,如果在向模型状态添加错误时指定自定义错误消息,将显示它.但是,如果添加了一个异常(对于接受异常的AddModelError有一个重载,另一个重载异常,另一个重载一个字符串;实现IDataErrorInfo就像字符串大小写一样),而不是一个字符串错误消息,只有在modelState为非空,然后我们给你一个通用消息,而不是异常的错误消息.
更新
Does ValidationSummary use ErrorMessage and ValidationMessage use InnerException.Message?
是的,这或多或少的效果.就像我说的,我觉得这是一个bug.
UPDATE2
Microsoft更新了GetUserErrorMessageOrDefault函数,如here所示.
private static string GetUserErrorMessageOrDefault(HttpContextBase httpContext,ModelError error,ModelState modelState) { if (!String.IsNullOrEmpty(error.ErrorMessage)) { return error.ErrorMessage; } if (modelState == null) { return null; } string attemptedValue = (modelState.Value != null) ? modelState.Value.AttemptedValue : null; return String.Format(CultureInfo.CurrentCulture,GetInvalidPropertyValueResource(httpContext),attemptedValue); }
c# – Silverlight Programmatical Drawing(从Windows Forms转换为Silverlight)
bmp = new Bitmap(columns*32,rows*32); graphics = Graphics.FromImage(bmp); pictureBox1.Size = new Size(columns * 32,rows * 32); pictureBox1.Image = bmp;
这我用来填充Windows窗体中的图形,
private void drawImageInBox(Image src,int BoxX,int BoxY,int Offset = 0) { graphics.DrawImage(src,new Point((BoxY * 32) + Offset,(BoxX * 32) + Offset)); }
当所有操作完成后我只刷新PictureBox,
pictureBox1.Refresh();
我如何在Silverlight xaml中实现这一目标?
解决方法
在你的XAML中:
<Grid x:Name="world_grid" Width="100" Height="100"> <Grid.RowDeFinitions> <RowDeFinition Height="*" /> <!--Repeat this for however many rows you need --> </Grid.RowDeFinitions> <Grid.ColumnDeFinitions> <ColumnDeFinition Width="*" /> <!--Same here,for columns--> </Grid.ColumnDeFinitions> </Grid>
在你的代码隐藏中:
for each image you need to add: Image img = new Image(); img.source = new Uri("some/dir/img.png"); // coding in-place,can't remember Syntax world_grid.Children.Add(img); Grid.SetRow(img,0); // places this image in row 0 Grid.SetColumn(img,5); // places this image in column 5
一个非常重要的注意事项:每次“刷新”您的“世界”时,请确保在重新添加之前删除相应的图像!更好的是,您可以在某些数组中跟踪这些图像,并更改其行/列.如果需要,可以将图像的可见性设置为隐藏/折叠.
Charlie Calvert: Silverlight Simple Animation
原作者:Charlie Calvert
原文地址: http://blogs.msdn.com/charlie/archive/2009/04/14/silverlight-simple-animation.aspx
This post is one of series on Silverlight. In this article the focus is on a technique that uses a timer to produce simple animations. I will follow this post with at least one additional article on Silverlight animation.
Silverlight has several built in techniques for animating controls. Many of these technologies are particularly useful for creating simple animations meant to decorate a web page with eye catching movement that draws the reader’s attention. In this post I will skip over these decorative technologies,and instead show how to create a simple animation using a technique similar to those used in many games.
这篇随笔是Silverlight系列随笔之一。其主要关注点在于一项使用计时器(Timer)来创建简单动画的技术。紧跟着这篇随笔,我会再额外发表至少一篇有关Silverlight动画的文章。
Silverlight有几种内置的技术使控件表现出动画效果。这些技术中大多数都对创建简单动画特别有用。这些动画意味着可以利用眼睛善于捕获运动的特点来修饰一个网页,从而引起读者的注意。在这篇随笔中,我将越过这些修饰性的技术,而展示一下如何使用与在很多游戏中使用的动画技术类似的技术来创建一个简单动画。
Though Silverlight is a web technology,the technique I will focus on is very similar to the same technology you would use in most standard programming languages such as C++ or Delphi. Though the animation technology I will focus on is often used in game programming,there are many different reasons why you might want to create this kind animation,particular in scientific programming,or code that attempts to illustrate complex numeric data.
尽管Silverlight是一项Web技术,但我将关注的技术与您在像C++或Dephi这样的标准编程语言中所使用的技术类似。虽然我将关注的动画技术通常被用于游戏编程,但您或许也有很多不同的理由想将其用于创建其他种类的动画,尤其是科学类的编程或者是试图演示复杂的数值数据的代码。
You will find that Silverlight makes the type of animation I want to focus on very simple. As such,it makes a good place to start an exploration of Silverlight animation. I want to emphasize,however,that there are other Silverlight techniques that use Storyboards and the DoubleAnimation and PointAnimation controls that might be more appropriate if you just want to add a bit of color to a web page. You can add a bit more complexity to those technologies by exploring key frames. See,for instance,the DoubleAnimationUsingKeyFrames control.
您会发现Silverlight使我想关注的那种动画类型实现起来很简单。因此,这是一个探索Silverlight动画的良好开端。然而,我想强调一下,如果您只是想对一个网页稍微润色一下,那么其他的使用Storyboard、DoubleAnimation和PointAnimation的Silverlight技术可能更符合您的需要。通过探索关键帧(Key Frame)的使用,您能够为这些技术再增加一点复杂度。您可以以DoubleAnimationUsingKeyFrames控制为例参考一下关键帧的使用。
In the example shown in this post I will create two simple “sprites” that I will animate by moving them smoothly and rapidly at an angle across a web page,as shown in figure 1. In figure 1,the blue Rectangle with the red border started its brief but illustrIoUs career near the upper right corner of the green field,and is moving down toward the bottom left corner. The purple and blue gradient image started at the upper left corner and is moving at an angle toward the bottom right of the green Canvas control.
在这篇随笔所展示的例子中,我将创建两个简单的“小精灵”,并演示一个让它们平滑而快速斜穿过一个网页的动画,正如图1所示,在图1中,带有红色边框的蓝色矩形从绿色场地的接近右上角的位置开始了它的短暂而又辉煌的行程,朝着左下角移动而下。而具有蓝紫渐变颜色的图片则从左上角开始,朝着绿色Canvas控件的右下角斜穿而过。
figure 1: Two simple sprites moving at angles across a green field.
Below you can see a live version of this application. Because the animation is quite brief,you will need to press the refresh button to see it in action.
图1:两个简单的小精灵斜穿过一块绿色场地
下面你能够看到这个程序的真实运行版。因为动画非常短暂,所以你会需要按下刷新按钮来看到它的运行。
The sprites in this example move smoothly and at a reasonable pace across the green surface. This is very important,as users frequently denigrate applications that have jerky or overly slow animations.
In the next post in this series I will show how to get more control over the sprites,and how to get them to “bounce” off the edges of a window so that they stay confined in a defined space,such as the green field shown here.
这个例子中的精灵们以一个合理的速度平滑地穿过绿色平面。这很重要,因为用户总是经常贬低那些拥有笨拙或过于缓慢的动画的应用程序。
在这个系列的下一篇随笔中,我将展示如何对这些精灵施加更多的控制,展示如何使它们弹离窗口的边界,以便它们可以始终被限制在一个预定义的空间之内,比如这里所显示的绿色区域。
Silverlight’s reliance on WPF frequently leaves developers with a choice between implementing their logic in XAML or in standard C# code,or in some combination of the two. Perhaps because my background is a C# developer,I tend to write only a minimal amount of XAML,and to implement most of my logic in C# code.
The XAML for this example is extremely simple:
Silverlight脱胎于WPF这一点,使开发者可以做出一种选择,是将他们的逻辑实现在XAML中还是在标准的C#代码中,或者是这两种形式的某种结合。或许因为我的背景是一名C#开发者,所以我倾向于只写少量的XAML代码,而以C#代码形式实现我的大部分逻辑。
这个例子的XAML代码非常简单:
The code for the UserControl and the Grid is boilerplate Silverlight code produced by the IDE when any new Silverlight project is created. I’ve added only three items:
l A Canvas called myCanvas which has an event called StartTimer that is called when the Canvas is first loaded
l A blue and red Rectangle control that is 25 pixels square
l An Image control which is also 25 pixels square. It is referenced inside the program as myImage
UserControl和Grid的代码是当任何Silverlight项目被创建的时候都会由集成开发环境(IDE)生成的样板Silverlight代码。我只添加了三项:
l 一个被命名为myCanvas的Canvas,它有一个叫做StartTimer的事件处理方法,这个方法将在Canvas被第一次加载时调用。
l 一个25像素大小、红色边框、蓝色背景的正方形的矩形控件。
l 一个同样25像素大小的正方形的图片控件,它在程序中以myImage引用。
The XAML puts both controls in the upper left corner of the Canvas,which means that in design mode one will be hidden behind the other. The C# code I show in the next section moves the Rectangle off to the right of the Canvas,so that it has a unique location at run time.
XAML代码将两个控件都放到了Canvas的左上角,也就是说,在设计模式下,其中一个控件将被隐藏到另外一个的后面。下一小节我展示的C#代码将矩形控件移动到了Canvas的右边,以便它在运行时有一个独立的位置。
The Timer
Animations of the kind shown here are usually run off a timer which produces a kind of miniature application loop that is called at regular intervals and which acts as engine to drive the animation forward. The loop is started when the Canvas is loaded:
计时器(Timer)
这里展示的这种动画通常基于一个计时器(timer)运行,这个计时器以有规律的间隔调用一种小型程序循环,这种小型程序循环担当引擎来驱动动画向前播放。这个循环在Canvas被加载时启动:
private void StartTimer(object sender,RoutedEventArgs e)
{
System.Windows.Threading.dispatcherTimer mydispatcherTimer =
new System.Windows.Threading.dispatcherTimer();
// Call the timer once every 10 milliseconds
mydispatcherTimer.Interval = new TimeSpan(0,10);
mydispatcherTimer.Tick += new EventHandler(MoveShapes);
mydispatcherTimer.Start();
}
This code is pulled nearly verbatim from the Silverlight documentation. It begins by creating a timer,then asks that the timer be fired once every ten milliseconds. A method called MoveShapes will be called whenever the timer is fired. Finally the code Starts the timer.
Here is the MoveShapes method,which is called by the timer once every ten milliseconds:
这段代码是从Silverlight文档中几乎一字不差地摘录下来的。它以创建一个计时器(timer)开始,随后让计时器每10毫秒触发一次。每次计时器被触发,一个叫做MoveShapes的方法就会被调用。
这是MoveShapes方法的代码,它每10毫秒就被计时器调用一次:
Double imageX = 0.0; Double imageY = 0.0; Double rectX = 275.0; Double rectY = 1.0; Double incValue = 1.0;
public void MoveShapes(object o,EventArgs sender) { imageX += incValue; imageY += incValue; rectX -= incValue; rectY += incValue; myRect.SetValue(Canvas.LeftProperty,rectX); myRect.SetValue(Canvas.TopProperty,rectY); myImage.SetValue(Canvas.LeftProperty,imageX); myImage.SetValue(Canvas.TopProperty,imageY); }
This method is passed two parameters. The first is copy of the timer. You can use this object to disable or change the traits of the timer.
这个方法被传递进两个参数。第一个参数是计时器(timer)实例的引用。你可以使用这个对象来禁用计时器或者改变计时器的行为。
This code in the MoveShapes covers several lines,but its structure is very simple. I’ve declared values to track the current X and Y location of the upper left hand corner of the Image and Rectangle controls. Note that I initialize the rectX field to 275.0. It is this value that moves the Rectangle control over to he right of the Canvas at program start up,so that it is no longer hidden behind Image control. Needless to say,in the next article in this series I will create separate objects for each sprite. At this stage however,I’m focusing on showing you the basic animation techniques in the least possible amount of code.
MoveShapes方法的代码有好几行,但是它的结构却非常简单。我声明了一些值来跟踪图片控件和矩形控件左上角顶点的当前X和Y坐标值。注意,我将rectX字段的值初始化为275.0。这个值也正是在程序启动时矩形控件被移动到Canvas右边的初始位置,以便它不再被隐藏在图片控件之后。无需多说,在这个系列的下一篇文章,我将为每个精灵创建单独的对象。然而在现阶段,我将集中精力用尽可能少的代码向您展示基本的动画技术。
The last lines show how to call the SetValue method of the Rectangle and Image control in order to move the control across the surface of the Canvas. Silverlight provides us with a nice bonus feature here by automatically handling this transformation. In particular,it erases the original image of the control and then repaints it in the new location. In most computer languages,I would have had to manually write the code to erase the old image.
最后几行代码演示了如何调用矩形控件和图片控件的SetValue方法来移动控件穿过Canvas表面。在这里Silverlight通过自动处理这种转换为我们提供了一个很棒的优秀特性。尤其是,它擦除控件的原有图像然后再在新位置重新绘制图像。在大部分计算机编程语言中,我通常都不得不手工编写代码来擦除原有的图像。
Note that the MoveShapes method begins by incrementing or decrementing the fields that specify the location of the controls. This allows us to define how we move the controls across the surface of the Canvas. It is,the call to SetValue that actually transforms the location of the controls. The end result is a smooth animation of the controls across the surface of their container.
注意,MoveShapes方法通过增加或减小指定控件位置的字段的值来开始运行的。这允许我们定义怎样移动控件穿过Canvas表面。然而,是对SetValue这个方法的调用实际变换了控件的位置。结果就是产生了这些控件平滑地穿过他们容器表面的动画效果。
The best way to see this animation in action is to download the code and try it yourself. Remember that you need to first install the Silverlight integration for Visual Studio 2008,as described in the Get Started section of the Silverlight web site.
查看这段代码的实际动画效果最好的方式是您下载代码并亲自试试。记住,您首先需要安装Visual Studio 2008的Silverlight集成扩展,正如Silverlight官方网站的入门(Get Started)部分中所描述的一样。
Summary
The technique for animating controls that I’ve described in this article is very easy to use. Silverlight provides all the tools we need to set up simple animation without requiring any real effort on our part. As a result we can focus our energy on simply describing the path that we want our controls to follow. In particular,you need only:
l Set up a timer that calls a method you define at discreet intervals.
l Define the method called by the timer,and ensure that it contains logic for moving your controls.
总结
我在这边文章中所叙述的控件动画技术非常易于使用。Silverlight提供了所有我们需要的工具来创建简单动画,而不需要我们这边付出太多努力。因此我们可以把精力集中在简单明了地描述我们想让控件运动的路径。尤其是,你只需:
l 设置一个计时器,以谨慎设定的时间间隔调用您预先定义的一个方法。
l 实现被计时器调用的那个方法,确保它包含移动你的控件的逻辑。
As mentioned above,I’ll follow this post with at least one additional article that describes additional techniques for animating sprites. Those techniques require us to write a bit more code than that shown here,but at heart they are also very simple and easy to understand.
Download the SilverlightAnimatedTimer01.zip file containing the sample code from the LINQ Farm.
正如上文提到的,我会紧随着这篇随笔再发表至少一篇额外的文章描述使精灵产生动画效果的附加技术。这些技术相比这里展示的需要我们再多写一些代码。但凭心而论,它们也很简单并且易于理解。
可以从“LINQ Farm”上下载包含示例代码的SilverlightAnimatedTimer01.zip文件。
REF:http://www.cnblogs.com/Ricky81317/archive/2009/06/05/1497029.html
我们今天的关于Silverlight ValidationSummary不显示异常的小问题和silverlight plug-in没有响应的分享已经告一段落,感谢您的关注,如果您想了解更多关于ASP.NET MVC Html.ValidationSummary(true) 不显示模型错误、asp.net MVC – ValidationSummary不显示、c# – Silverlight Programmatical Drawing(从Windows Forms转换为Silverlight)、Charlie Calvert: Silverlight Simple Animation的相关信息,请在本站查询。
本文标签: