Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
C#
public partial class MainWindow : Window
    {
        System.Timers.Timer   t=new   System.Timers.Timer();
                              t.Interval=5000;
         
        public MainWindow()
        {
            this.InitializeComponent();            
            // Insert code required on object creation below this point.
        }
        
   private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
        {            
            this.media1.Play();
            //mel_Copy.Stop();
            
            t.Enabled=true;
            t.Tick+=new System.EventHandle(this.timer1_Tick);    //here        
            
            //B1
        }

       private void timer1_Tick(object sender, System.EventArgs e)   
                  {
    this.media1.Stop();    
                    }
        }
}


I'm programming in Expression blend 3,
I want to use a timer in WPF that when the user clicks the button1, event occurs after 5 sec (for example), but it seems WPF does not have the
Tick event ! ( t.Tick) :confused: :(
I've added System.Timers;
What shall I do?
Posted
Updated 15-Feb-10 20:54pm
v4

Use the DispatcherTimer object instead of System.Timers.Timer. BTW, this is EASILY answered by using google.
 
Share this answer
 
Hi,
Think you are looking for the Elapsed event
See this link[^]

Hope it helps :)
 
Share this answer
 
v2
If you can't set something in XAML, you need to set it in C# or VB.NET, as the documentation says. You posted code, so that's where you have to do it.
 
Share this answer
 
C#
public TimeSpan Interval { get; set; }

Visual C++
public:
property TimeSpan Interval {
TimeSpan get ();
void set (TimeSpan value);
}

J#
/** @property */
public TimeSpan get_Interval()
/** @property */
public void set_Interval(TimeSpan value)

JScript
public function get Interval () : TimeSpan
public function set Interval (value : TimeSpan)

XAML
You cannot set this property in XAML.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900