Using System; Using System. Windows; Using System. Windows. Controls; Using System. Windows. Input; Using System. Windows. Media; Using System. Windows. Media. Animation; Using Microsoft. Phone. Controls; Using System. Windows. Media. Imaging; Namespace PhoneTest1 { Public partial class MaainPage: PhoneApplicationPage { /// <Summary> /// Record the last click /// </Summary> Canvas _ LastCanvas = new Canvas (); /// <Summary> /// Animated Image /// </Summary> Image Img_Story = new Image (); /// <Summary> /// Definition white /// </Summary> SolidColorBrush WhiteColorBrush = new SolidColorBrush (); /// <Summary> /// Defines gray /// </Summary> SolidColorBrush OtherColorBrush = new SolidColorBrush (); Public MainPage () { InitializeComponent (); This. Loaded + = new RoutedEventHandler (MainPage_Loaded ); } Void MainPage_Loaded (object sender, RoutedEventArgs e) { // Set the color WhiteColorBrush. Color = Color. FromArgb (255,255,255,255 ); OtherColorBrush. Color = Color. FromArgb (255, 61, 61, 61 ); Boolean _ IsFirstAddElement = false; For (int I = 0; I <10; I ++) { Canvas _ Canvas = new Canvas (); _ Canvas. Height = 60; TextBlock _ TextBlock = new TextBlock (); _ TextBlock. Text = I. ToString () + ": Test Program"; // rename it by yourself Canvas. SetLeft (_ TextBlock, 30); // 30 is left of the canvas. you can adjust it yourself. Canvas. SetZIndex (_ TextBlock, 100); // sets the layer to prevent text from being overwritten. _ TextBlock. FontSize = 30; _ Canvas. Children. Add (_ TextBlock ); If (! _ IsFirstAddElement) { _ IsFirstAddElement = true; This. Img_Story.Source = new BitmapImage (new Uri ("/PhoneTest1; component/Image/Test. PNG", UriKind. RelativeOrAbsolute )); Canvas. SetLeft (Img_Story, 0); // 30 is left of the canvas. you can adjust it yourself. Canvas. SetZIndex (Img_Story, 0); // sets the layer to prevent text from being overwritten. _ Canvas. Children. Add (this. Img_Story ); This. _ LastCanvas = _ Canvas; _ TextBlock. Foreground = WhiteColorBrush; } Else { _ TextBlock. Foreground = OtherColorBrush; } // Click an event _ TextBlock. MouseLeftButtonDown + = new MouseButtonEventHandler (_ TextBlock_MouseLeftButtonDown ); // Add the element to the container This. Panel_Element.Children.Add (_ Canvas ); } } /// <Summary> /// Click Event /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "e"> </param> Void _ TextBlock_MouseLeftButtonDown (object sender, MouseButtonEventArgs e) { TextBlock Txt_Road = sender as TextBlock; // Retrieve the page element and set the text color Foreach (FrameworkElement fe in this. Panel_Element.Children) { If (fe is Canvas) // retrieves TextBlock { Canvas _ Canvas = (Canvas) fe; TextBlock chk = (TextBlock) _ Canvas. Children [0]; If (chk. Equals (Txt_Road )) { _ LastCanvas. Children. Remove (this. Img_Story ); _ Canvas. Children. Add (this. Img_Story ); This. _ LastCanvas = _ Canvas; Chk. Foreground = WhiteColorBrush; // set the current click to white CreateStoryBoard (); } Else { Chk. Foreground = OtherColorBrush; // other changes back to the original default color } } } } /// <Summary> /// Create a click Animation /// </Summary> Private void CreateStoryBoard () { Storyboard storyboard = new Storyboard (); // instantiate Storyboard // Instantiate the X axis animation object DoubleAnimation doubleAnimationX = new DoubleAnimation (); DoubleAnimationX. Duration = new Duration (TimeSpan. FromMilliseconds (500); // sets the animation delay time. DoubleAnimationX. From = 0; // sets the animation initial value. DoubleAnimationX. To = 10; // sets the animation completion value. Storyboard. SetTarget (doubleAnimationX, this. Img_Story); // sets the animation operation object Storyboard. SetTargetProperty (doubleAnimationX, new PropertyPath ("(Canvas. Left)"); // you can specify attributes of an animation operation object. Storyboard. Children. Add (doubleAnimationX); // load the animation to the Storyboard // Start the animation Storyboard. Begin (); } } } |