2011-08-30 3 views
3

ListBox에 대해 The Live Tile Effect을 만들고 싶습니다.ListBoxItem에 라이브 타일 효과를 만들려면 어떻게해야합니까?

0에서 ListBox.Items.Count 사이의 임의의 숫자를 만든 다음 그걸 ListBoxItem으로 가져 와서 애니메이션으로 만들 것을 생각했습니다.

저는 애니메이션 용으로 this을 사용하고 있습니다.

그래서 XAML에서 기본 애니메이션과 같을 것이다 :

xmlns:pl="clr-namespace:Planerator" 

<pl:Planerator x:Name="planerator"> 
         <Image Name="logo" Source="somePath"> 
          <Image.Triggers> 
           <EventTrigger RoutedEvent="Image.MouseLeave"> 
            <BeginStoryboard> 
             <Storyboard> 
              <DoubleAnimation Storyboard.TargetName="planerator" 
                  Storyboard.TargetProperty="RotationX" 
                  From="0" To="360" 
                  BeginTime="0:0:0" 
                  Duration="0:0:1" 
                  AutoReverse="False"/> 
             </Storyboard> 
            </BeginStoryboard> 
           </EventTrigger> 
          </Image.Triggers> 
         </Image> 
        </pl:Planerator> 

이 내가 지금까지 시도한 것입니다 :

<ListBox Name="someList" 
     Loaded="someList_Loaded"> 
</ListBox> 

someList_Loaded 방법 : 이제 내

Random random = new Random(); 
    Planerator planerator = new UI.WPF.Planerator(); 
    planerator.Name = "planerator"; 

    someList.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, 
      new Action(
       delegate() 
       { 
      do 
      { 
       //planerator.Child = (ListBoxItem)someList.Items[random.Next(0, someList.Items.Count - 1)]; 

       DoubleAnimation myDoubleAnimation = new DoubleAnimation() 
       { From = 0, To = 360, Duration = new Duration(TimeSpan.FromMilliseconds(1)) }; 

       Storyboard.SetTargetName(planerator, planerator.Name); 
       Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath("RotationX")); 

       Storyboard storyboard = new Storyboard(); 
       storyboard.Children.Add(myDoubleAnimation); 

       someList.MouseMove += delegate(object newSender, MouseEventArgs args) 
       { 
        storyboard.Begin(currentListItem); 
       }; 

       //Sleep 30sec 
      }while(true); 
     } 
)); 

문제 :

  1. 스레드 본문의 첫 줄. 해당 전송이 유효하지 않습니다. 무작위로 ListBoxItem을 받고 planerator.Child에 지정하면 어떻게 될까요?

  2. 이 줄 //Sleep 30sec : 여기에 대기 또는 수면을 어떻게 추가하나요?

  3. The Live Tile Effect을 만들려면이 방법이 유용할까요? 더 좋은 방법이 있습니까?

  4. 주요 성능 문제가 있습니까?

편집 :

  1. ItemContainerGenerator generator = someList.ItemContainerGenerator; ListBoxItem currentListItem = generator.ContainerFromIndex(random.Next(0, someList.Items.Count - 1)) as ListBoxItem;

편집 :

이 내가 지금까지 무엇을 가지고,하지만 아무 일도 발생하지 :

lstNotifications.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, 
        new Action(
         delegate() 
         { 
          ItemContainerGenerator generator = lstNotifications.ItemContainerGenerator; 
          ListBoxItem currentListItem = generator.ContainerFromIndex(random.Next(0, lstNotifications.Items.Count - 1)) as ListBoxItem; 

          var tempObject = Content; 
          Content = null; 

          planerator.Child = currentListItem; 

          Content = tempObject; 

          this.RegisterName(planerator.Name, planerator); 

          DoubleAnimation myDoubleAnimation = new DoubleAnimation() { From = 0, To = 360, Duration = new Duration(TimeSpan.FromMilliseconds(1)) }; 

          Storyboard.SetTargetName(planerator, planerator.Name); 
          Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Planerator.RotationXProperty)); 

          Storyboard storyboard = new Storyboard(); 
          storyboard.RepeatBehavior = RepeatBehavior.Forever; 
          storyboard.Children.Add(myDoubleAnimation); 

          storyboard.Begin(currentListItem); 
         } 
        )); 

왜 아무 일도 일어나지 않으십니까?

답변

1

은 당신이 달성 하려는지 모르겠지만 여기거나 도움이되지 않을 수도 있습니다 몇 가지 있습니다 :

1 - 내가 아는 한 Planerator.Child 유형의 ListBoxItem의이 아닌 - 그래서 그런 유형을 할당 faills - 해당 속성의 유형을 확인합니다.

2 - System.Threading.Thread.Sleep (30000);을 (를) 사용해 보셨습니까? ?

3, 4 내가 대답 할 수없는하지만 어쩌면 그렉 Schechter가 도울 수 :

Dead Simple 3D in WPFImplementation Details Of The Planerator

관련 문제