Silverlight Magic Cube Practice 3.

Source: Internet
Author: User

Ha,... Coming again ~

1. Create a button and write "Play Game" in the content. (You can write this as you like. You can do it too !)

2. Create a Canvas container and display the one that is flashing. (why is it not an Image? The degree of freedom of the container is relatively high. · haha)

3. then I began to think about the one that flashed and painted on the Blend, haha... yes, but this flash will be used later. Obviously, it is not scientific to draw so, this is a flash... it is more reasonable to use your own code. Well, it should be better. This can be written like this.

Speak nonsense ,. See the following

Create a Common class ~~~

/// <Summary> /// obtain the animation /// </summary> /// <param name = "Index"> </param> /// <param name = "Max"> </param> /// <param name = "url"> </param> // <param name = "style"> 1: loop 0: no loop </param> // <returns> </returns> public static ImageSource GetGif (ref int Index, ref int Max, ref bool isHit, string url, int style) {ImageSource source = null; if (Index <Max) {source = Common. getImgSource (url); isHit = true; Index ++;} else {if (style = 1) {// loop Index = 0; return null ;} else {// non-cyclic isHit = false; return null ;}} return source ;} /// <summary> /// obtain the image source /// </summary> /// <param name = "url"> </param> /// <returns> </returns> public static ImageSource GetImgSource (string url) {ImageSource source = new BitmapImage (GetUri (url); return source ;} /// <summary> /// obtain the resource /// </summary> /// <param name = "url"> </param> /// <returns> </returns> public static Uri GetUri (string url) {Uri uri = new Uri (url, UriKind. relative); return uri ;}

The amount of resources read from WPF, silverlight, and Dongdong is... Uri, so. You need to change the previous idea of direct Path, · (if you directly use Path · he will pop up a denial of access · and other error messages ··)

 

5. Create a user control named Hit in the UserControls folder. Well,

6. designing this Hit. xaml is actually nothing. It is to define its size and add an Image element. The background is the focus,

<UserControl x:Class="SilverlightMusicHit.Hit"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d"    d:DesignHeight="135" d:DesignWidth="135">    <Image Grid.Column="1" Height="135"   HorizontalAlignment="Left" Name="imgHit" Stretch="Fill" VerticalAlignment="Top" Width="135" /></UserControl>

7. Edit the background

Using System; using System. collections. generic; using System. linq; using System. net; using System. windows; using System. windows. controls; using System. windows. documents; using System. windows. input; using System. windows. media; using System. windows. media. animation; using System. windows. shapes; using System. windows. media. imaging; namespace SilverlightMusicHit {public partial class Hit: UserControl {# region variable /// <summary> /// Hit display index, 0 bad, 1 perfect // </summary> public int hitDisIndex = 0; // <summary> // display type, 1 loop, 0 is not cyclic // </summary> public int HitStyle = 0; /// <summary> /// Hit click index /// </summary> public bool isHit = false; /// <summary> /// Hit display speed/MS /// </summary> private int speed = 30; /// <summary> /// number of images displayed in Hit /// </summary> private int hitMax = 6; /// <summary> /// Hit display list /// </summary> private string [] hitUrl = {"Image/PicHit/gauge_bad _", "Image/PicHit/gauge_perfect _"}; // <summary> // timer // </summary> private Storyboard _ timer; /// <summary> /// Hit image index /// </summary> private int hitIndex = 0; # endregion public Hit () {InitializeComponent (); // create a timer _ timer = new Storyboard (); _ timer. duration = new Duration (TimeSpan. fromMilliseconds (speed); _ timer. completed + = new EventHandler (_ timer_Completed); _ timer. begin ();} void _ timer_Completed (object sender, EventArgs e) {string url = string. format (".. /{0} {1} {2} ", hitUrl [hitDisIndex], hitIndex ,". png "); imgHit. source = Common. getGif (ref hitIndex, ref hitMax, ref isHit, url, HitStyle); if (isHit) _ timer. begin (); else _ timer. stop ();}}}

Most of them can understand the story board... the point is... StoryBoard. You can see it at MSDN, · ha · still be good at reading MSDN · very good and powerful

StoryBoard

Provides the container timeline of object and attribute target information for the sub-animation of the container.

 

Duration Gets or sets the playback duration of this timeline, instead of counting repetition. This is a Dependency Property. (Inherited from Timeline .)

 

 

Completed This occurs when the timeline is completely played: it no longer enters its activity cycle. (Inherited from Timeline .)

 

 

All right... HIT is complete in a flash ,··

 

Press F5 to run. . No?

Don't worry, you are right. You are not doing well yet.

 

8. Return to the MainPage editing background and write the following code in his constructor:

Public MainPage () {InitializeComponent (); // create Hit hit = new Hit (); Random rand = new Random (); hit. hitDisIndex = rand. next (0, 1); hit. hitStyle = 1; this. hit. children. add (hit );}

Press F5 again, amount... Not yet? Oh, no images, of course no ,···

 

9. Create a PicHit folder in the Image folder and add the folder as a piece.

Http://www.vdisk.cn/down/index/8805162A4337

 

 

Well, now press F5. Hmm ··

 

Name: 5 + x

 

Reference articles and books:

WPF sunflower collection

Development Technology and essence of silverlight2.0

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.