내 채팅 응용 프로그램에서는 메시지를 보내는 사람이 누구인지 그리고 자신의 채팅 창이 사용자 측에서 열려 있지 않은 경우 목록 상자에서 그의 이름이 깜박이면서 수신 메시지를 사용자에게 알리는 사용자 목록이 있습니다. 사용자가 보낸 사람을 선택하면 애니메이션이 제거됩니다.하지만 마지막으로 애니메이션이 적용된 요소에 대해서만 애니메이션이 중지됩니다.스토리 보드 애니메이션을 ListBoxItem에 적용하는 것을 멈추는 방법?
private void OnlineUserListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBoxItem listBoxItem = OnlineUserList.ItemContainerGenerator.ContainerFromItem(OnlineUserList.SelectedItem) as ListBoxItem;
if (listBoxItem != null && listBoxItem.HasAnimatedProperties)
{
blinkStoryboard.Stop(listBoxItem);
}
}
: 아래 는private void BlinkSenderUsername(int index, string userRole)
{
blinkAnimation = new DoubleAnimationUsingKeyFrames();
blinkAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))));
blinkAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(250))));
ListBoxItem target = new ListBoxItem();
target = OnlineUserList.ItemContainerGenerator.ContainerFromIndex(index) as ListBoxItem;
OnlineUserList.ScrollIntoView(target);
blinkStoryboard = new Storyboard
{
Duration = TimeSpan.FromMilliseconds(900),
RepeatBehavior = RepeatBehavior.Forever,
};
Storyboard.SetTarget(blinkAnimation, target);
Storyboard.SetTargetProperty(blinkAnimation, new PropertyPath(OpacityProperty));
blinkStoryboard.Children.Add(blinkAnimation);
blinkStoryboard.Begin(target, true);
}
및 선택에
는 (선택에 애니메이션을 중지) 목록 상자의 변경 이벤트를 내가 ListBoxItem의에 애니메이션을 적용하기 위해 사용하고있는 코드입니다누구나 제안 할 수 있습니까, 내가 뭘 잘못하고 있니? (재이의 대답에 따라) 편집
: -
static void MyClassStaticConstructor()
{
BlinkAnimation = new DoubleAnimationUsingKeyFrames();
BlinkAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))));
BlinkAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(250))));
BlinkStoryboard = new Storyboard
{
Duration = TimeSpan.FromMilliseconds(900),
RepeatBehavior = RepeatBehavior.Forever,
};
BlinkStoryboard.Children.Add(BlinkAnimation);
}
private void BlinkSenderUsername(int index, string userRole)
{
// There is no need to instantiate a ListBoxItem
//ListBoxItem target = new ListBoxItem();
ListBoxItem target = OnlineUserList.ItemContainerGenerator.ContainerFromIndex(index) as ListBoxItem;
if (target == null) return;
MyClassStaticConstructor();
Storyboard.SetTarget(BlinkAnimation, target);
Storyboard.SetTargetProperty(BlinkAnimation, new PropertyPath(OpacityProperty));
BlinkStoryboard.Begin(target, true);
}
및 목록 상자에서 selectionChanged 이벤트 :
이private void OnlineUserListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBoxItem listBoxItem = OnlineUserList.ItemContainerGenerator.ContainerFromItem(OnlineUserList.SelectedItem) as ListBoxItem;
if (listBoxItem != null && listBoxItem.HasAnimatedProperties)
{
BlinkStoryboard.Stop(listBoxItem);
}}
"애니메이션이 먼저 적용된 요소를 제외한 다른 모든 목록 상자 항목에 대해 애니메이션이 중지됩니다." 방법? – Jai
애니메이션이 처음 적용된 SenderName을 제외하고는 다른 모든 Senders에 대한 애니메이션을 중지 할 수 있습니다. 즉 사용자가 UserA에서 메시지를 받으면 그의 이름이 깜박이기 시작하고 Againg 사용자가 UserB로부터 메시지를받습니다. 깜박임 시작), UserB를 클릭하면 애니메이션이 중지되지만 UserA를 클릭하면 깜박입니다.). 지금은 분명합니까? – NewbieCoder
코드를 다시 디버그하고 마지막으로 적용된 요소에 대해서만 애니메이션이 중지된다는 것을 알아야합니다. – NewbieCoder