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);
}
));
문제 :
스레드 본문의 첫 줄. 해당 전송이 유효하지 않습니다. 무작위로
ListBoxItem
을 받고planerator.Child
에 지정하면 어떻게 될까요?이 줄
//Sleep 30sec
: 여기에 대기 또는 수면을 어떻게 추가하나요?The Live Tile Effect
을 만들려면이 방법이 유용할까요? 더 좋은 방법이 있습니까?주요 성능 문제가 있습니까?
편집 :
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);
}
));
왜 아무 일도 일어나지 않으십니까?