2014-12-25 3 views
1

3 초 동안 만 레이블을 표시하고 사라질 것입니다. 나는 wpf 응용 프로그램에서 일하고있다. wpf에서 몇 초 동안 라벨을 표시하는 방법은 무엇입니까?

public DispatcherTimer timer = new DispatcherTimer(); 
timer.Tick += new EventHandler(timer_Tick); 

내가 함수

timer.Start(); 

private void timer_Tick(object sender, EventArgs e) 
{ 
     /* 
     if timer equals 3 seconds then 
     timer.stop(); 
     lblToast.Visibility = Visibility.Hidden; 
     else 
     lblToast.Visibility = Visibility.Visible; 
     */ 
} 

이 올바른 방법은에서 타이머를 시작? 또는 다른 쉬운 방법이 있습니까? 이 매우 easily.For 애니메이션 방문을 할 수

답변

4

당신의 Interval 3000로 설정 한 후 바로 Tick 경우에 라벨을 숨 깁니다.

+0

timer.Interval = new TimeSpan (0, 0, 3); ' 작동합니다. 고맙습니다. – Dhaval

3

사용하여 WPF 애니메이션이 link

<Label Content="Hello World"> 
     <Label.Triggers> 
      <EventTrigger RoutedEvent="Loaded"> 
       <BeginStoryboard> 
        <Storyboard> 
         <ObjectAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="Visibility"> 
          <DiscreteObjectKeyFrame KeyTime="0:0:3" Value="{x:Static Visibility.Collapsed}"/> 
         </ObjectAnimationUsingKeyFrames> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
     </Label.Triggers> 
    </Label>