Microsoft 9GD00001 Computer Accessories User Manual


 
292 Microsoft Visual Studio 2010: A Beginner’s Guide
Double-clicking the StartStopButton control will generate this Click event handler in
the code-behind at MainPage.xaml.cs, shown in Listing 10-2.
Listing 10-2 Playing and stopping a video
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightDemoCS
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
VideoPlayer.AutoPlay = false;
}
private bool m_isPlaying = false;
private void StartStopButton_Click(
object sender, RoutedEventArgs e)
{
if (m_isPlaying)
{
VideoPlayer.Stop();
StartStopButton.Content = "Start";
m_isPlaying = false;
}
else
{
VideoPlayer.Play();
StartStopButton.Content = "Stop";