시간은 TimeSpan으로, 색상은 Color 클래스의 정적 메소드로 생성할 수 있다.

TimeSpan.FromSeconds(2);
Color.FromArgb(255, 255, 0, 0);


저작자 표시 비영리 동일 조건 변경 허락
Posted by 데모집팀 황리건

http://msdn.microsoft.com/en-us/library/cc189019(VS.96).aspx

  • Create a DoubleAnimation

  • Create a Storyboard

  • Begin the Storyboard in response to an even

  • private void Create_And_Run_Animation(object sender, EventArgs e)
    {
        // Create a red rectangle that will be the target
        // of the animation.
        Rectangle myRectangle = new Rectangle();
        myRectangle.Width = 200;
        myRectangle.Height = 200;
        Color myColor = Color.FromArgb(255, 255, 0, 0);
        SolidColorBrush myBrush = new SolidColorBrush();
        myBrush.Color = myColor;
        myRectangle.Fill = myBrush;

        // Add the rectangle to the tree.
        LayoutRoot.Children.Add(myRectangle);

        // Create a duration of 2 seconds.
        Duration duration = new Duration(TimeSpan.FromSeconds(2));

        // Create two DoubleAnimations and set their properties.
        DoubleAnimation myDoubleAnimation1 = new DoubleAnimation();
        DoubleAnimation myDoubleAnimation2 = new DoubleAnimation();

        myDoubleAnimation1.Duration = duration;
        myDoubleAnimation2.Duration = duration;

        Storyboard sb = new Storyboard();
        sb.Duration = duration;

        sb.Children.Add(myDoubleAnimation1);
        sb.Children.Add(myDoubleAnimation2);

        Storyboard.SetTarget(myDoubleAnimation1, myRectangle);
        Storyboard.SetTarget(myDoubleAnimation2, myRectangle);

        // Set the attached properties of Canvas.Left and Canvas.Top
        // to be the target properties of the two respective DoubleAnimations.
        Storyboard.SetTargetProperty(myDoubleAnimation1, new PropertyPath("(Canvas.Left)"));
        Storyboard.SetTargetProperty(myDoubleAnimation2, new PropertyPath("(Canvas.Top)"));

        myDoubleAnimation1.To = 200;
        myDoubleAnimation2.To = 200;

        // Make the Storyboard a resource.
        LayoutRoot.Resources.Add("unique_id", sb);

        // Begin the animation.
        sb.Begin();
    }
    저작자 표시 비영리 동일 조건 변경 허락
    Posted by 데모집팀 황리건

    MSDN 실버라이트3 레퍼런스 중 : http://msdn.microsoft.com/en-us/library/cc189084(VS.95).aspx

    <Grid x:Name="LayoutRoot" Background="White">

      <!-- Just a TextBlock to show the output of the timer. -->
      <TextBlock Loaded="StartTimer" x:Name="myTextBlock" />
    </Grid>



     

    public void StartTimer(object o, RoutedEventArgs sender)
    {
        System.Windows.Threading.DispatcherTimer myDispatcherTimer = new System.Windows.Threading.DispatcherTimer();
        myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); // 100 Milliseconds
        myDispatcherTimer.Tick += new EventHandler(Each_Tick);
        myDispatcherTimer.Start();
    }

    // A variable to count with.
    int i = 0;

    // Raised every 100 miliseconds while the DispatcherTimer is active.
    public void Each_Tick(object o, EventArgs sender)
    {
        myTextBlock.Text = "Count up: " + i++.ToString();
    }


    저작자 표시 비영리 동일 조건 변경 허락
    Posted by 데모집팀 황리건
    비교적 간단한 구현 : http://wildermuth.com/2009/02/09/Drag_and_Drop_in_Silverlight_2

    public partial class Page : UserControl
    {
      bool isDragging = false;
      Point offset;
      // ...
    }
    

    void theDragon_MouseLeftButtonDown(object sender,
                                       MouseButtonEventArgs e)
    {
      // Mark that we're doing a drag
      isDragging = true;

      // Ensure that the mouse can't leave the dragon
      theDragon.CaptureMouse();

      // Determine where the mouse 'grabbed'
      // to use during MouseMove
      offset = e.GetPosition(theDragon);
    }

    void theDragon_MouseMove(object sender, MouseEventArgs e)
    {
      if (isDragging)
      {
        // Where is the mouse now?
        Point newPosition = e.GetPosition(LayoutRoot);
        info.Text = string.Concat("Position: ",
                                  newPosition.X,
                                  " x ",
                                  newPosition.Y);

        // Move the dragon via the new position less the offset
        theDragon.SetValue(Canvas.LeftProperty,
                           newPosition.X - offset.X);
        theDragon.SetValue(Canvas.TopProperty,
                           newPosition.Y - offset.Y);
      }
    }

    void theDragon_MouseLeftButtonUp(object sender, 
                                     MouseButtonEventArgs e)
    {
      if (isDragging)
      {
        // Turn off Drag and Drop
        isDragging = false;
    
        // Free the Mouse
        theDragon.ReleaseMouseCapture();
      }
    }

    MSDN Drag & Drop 샘플 : http://msdn.microsoft.com/en-us/library/cc189066(VS.96).aspx HitTest를 이용해서 오브젝트 추적 : http://nickssoftwareblog.com/2008/10/07/silverlight-20-in-examples-part-drag-and-drop-inside-out/

    드래그엔드롭 매니저 : http://www.codeplex.com/silverlightdragdrop
    저작자 표시 비영리 동일 조건 변경 허락
    Posted by 데모집팀 황리건
    C#에서는 eval()이나 ["오브젝트 이름"]을 사용할 수 없는 대신, FindName()을 이용해서 직접적으로 참조할 수 있다.

    VisualStateManager.GoToState(FindName("myCoverStates"+i),"position"+position,true);
    저작자 표시 비영리 동일 조건 변경 허락
    Posted by 데모집팀 황리건