开发者

How can i create The Live Tile Effect for a ListBoxItem?

I want to create a The Live Tile Effect for my ListBox.

I thought about creating a random number between 0 and ListBox.Items.Count and then taking that ListBoxItem and animating it.

I am using this for animation.

So a basic animation in XAML would look like this:

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>

This is what i have tried so far:

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

someList_Loaded Method:

    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);
      }
  ));

Now my problems:

  1. First line in the thread's body. That casting is not valid. How would i go about getting a random ListBoxItem and assigning it to planerator.Child?

  2. This line //Sleep 30sec: How would i add a wait or sleep here?

  3. For creating The Live Tile Effect, is this way viable or is there a better way?

  4. Will there be any major performance issues?

EDIT:

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

EDIT:

This is what i got so far, but nothing happens:

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);
                        }
                    ));

Any idea why nothing is happening?


Am not sure what you are trying to achieve but here are some things that may or may not help:

1 - As far as I know Planerator.Child is not of type ListBoxItem - so assigning it that type faills - check the type of that property.

2 - Have you tryed using System.Threading.Thread.Sleep(30000); ?

3 and 4 I can't answer but maybe Greg Schechter can help:

Dead Simple 3D in WPF and Implementation Details Of The Planerator

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜