Click here to Skip to main content
15,895,084 members
Articles / Web Development / ASP.NET

Silverlight YouTube Jukebox

Rate me:
Please Sign up or sign in to vote.
4.97/5 (72 votes)
27 Apr 2010CPOL12 min read 221.5K   3.2K   119  
Search and play YouTube videos inside a Silverlight 4.0 application! Learn about RIA Services, right-click event handling, themes, and styles.
  • mediastore.zip
    • MediaStore
      • _ReSharper.MediaStore
        • BuildScriptCache
          • .crc
          • .version
          • 0
          • 5
            • 36ffebe3.dat
        • DecompilerCache
        • ModuleIds.xml
        • NamedArguments
          • .crc
          • .version
          • 2
            • 68a91b39.dat
        • PdbInfo
          • b44f4be46623b83c18bcb9c7ef0ccf674da302c6
          • fa721ee25d1bd163495d202eeada5552c2f334cc
        • ProjectModel
          • ProjectModel.dat
        • Resources
          • .crc
          • .version
          • 0
          • 1
            • 1c34c2be.dat
        • SymbolCache.bin
        • TagPrefixes
          • .crc
          • .version
          • 0
          • 9
            • 4f91e12f.dat
        • TodoCache
          • .crc
          • .version
          • 5
          • 7
            • 4348e689.dat
        • WebsiteFileReferences
          • .crc
          • .version
        • WordIndex
          • .crc
          • .version
          • 1
            • 55d27f8f.dat
          • 3
          • 5
          • 8
          • 9
            • 7616753.dat
      • MediaStore.5.0.ReSharper.user
      • MediaStore.5.1.ReSharper.user
      • MediaStore.sln
      • MediaStore.suo
      • MediaStore.Web
      • MediaStore
        • App.xaml
        • App.xaml.cs
        • Assets
        • Bin
          • Debug
            • ActivityControl.dll
            • AppManifest.xaml
            • ar
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • bg
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • ca
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • cs
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • da
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • de
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • Divelements.SilverlightTools.dll
            • el
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • es
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • et
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • eu
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • fi
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • fr
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • he
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • hr
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • hu
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • id
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • it
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • ja
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • ko
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • lt
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • lv
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • MediaStore.dll
            • MediaStore.pdb
            • MediaStore.xap
            • ms
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • nl
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • no
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • pl
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • pt
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • pt-BR
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • ro
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • ru
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • sk
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • sl
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • sr-Cyrl-CS
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • sr-Latn-CS
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • sv
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • System.ComponentModel.DataAnnotations.dll
            • System.ComponentModel.DataAnnotations.xml
            • System.ServiceModel.DomainServices.Client.dll
            • System.ServiceModel.DomainServices.Client.Web.dll
            • System.ServiceModel.DomainServices.Client.Web.xml
            • System.ServiceModel.DomainServices.Client.xml
            • System.ServiceModel.Web.Extensions.dll
            • System.ServiceModel.Web.Extensions.xml
            • System.Windows.Controls.Data.DataForm.Toolkit.dll
            • System.Windows.Controls.Data.Input.dll
            • System.Windows.Controls.Data.Input.xml
            • System.Windows.Controls.dll
            • System.Windows.Controls.DomainServices.dll
            • System.Windows.Controls.DomainServices.xml
            • System.Windows.Controls.Navigation.dll
            • System.Windows.Controls.Navigation.xml
            • System.Windows.Controls.Theming.ExpressionDark.dll
            • System.Windows.Controls.Theming.ExpressionDark.pdb
            • System.Windows.Controls.Theming.Toolkit.dll
            • System.Windows.Controls.Theming.Toolkit.pdb
            • System.Windows.Controls.Theming.Toolkit.xml
            • System.Windows.Controls.xml
            • System.Windows.Data.dll
            • System.Windows.Data.xml
            • TestPage.html
            • th
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • tr
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • uk
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • vi
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • zh-Hans
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • zh-Hant
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
        • Controls
        • Generated_Code
        • GlobalSuppressions.cs
        • Helpers
        • Libs
          • ActivityControl.dll
          • Divelements.SilverlightTools.dll
          • System.Windows.Controls.Data.DataForm.Toolkit.dll
        • MainPage.xaml
        • MainPage.xaml.cs
        • MediaStore.csproj
        • MediaStore.csproj.user
        • Models
        • Properties
        • TrackContextMenu.xaml.cs
        • Views
        • Web
          • Resources
namespace MediaStore.Controls
{
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Shapes;
    using System.Windows.Threading;

    /// <summary>
    /// A control to provide a visual indicator when an application is busy.
    /// </summary>
    [TemplateVisualState(Name = VisualStates.StateIdle, GroupName = VisualStates.GroupBusyStatus)]
    [TemplateVisualState(Name = VisualStates.StateBusy, GroupName = VisualStates.GroupBusyStatus)]
    [TemplateVisualState(Name = VisualStates.StateVisible, GroupName = VisualStates.GroupVisibility)]
    [TemplateVisualState(Name = VisualStates.StateHidden, GroupName = VisualStates.GroupVisibility)]
    [StyleTypedProperty(Property = "OverlayStyle", StyleTargetType = typeof(Rectangle))]
    [StyleTypedProperty(Property = "ProgressBarStyle", StyleTargetType = typeof(ProgressBar))]
    public class BusyIndicator : ContentControl
    {
        /// <summary>
        /// Gets or sets a value indicating whether the BusyContent is visible.
        /// </summary>
        protected bool IsContentVisible { get; set; }

        /// <summary>
        /// Timer used to delay the initial display and avoid flickering.
        /// </summary>
        private DispatcherTimer _displayAfterTimer;

        /// <summary>
        /// Instantiates a new instance of the BusyIndicator control.
        /// </summary>
        public BusyIndicator()
        {
            DefaultStyleKey = typeof(BusyIndicator);
            _displayAfterTimer = new DispatcherTimer();
            _displayAfterTimer.Tick += new EventHandler(DisplayAfterTimerElapsed);
        }

        /// <summary>
        /// Overrides the OnApplyTemplate method.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            ChangeVisualState(false);
        }

        /// <summary>
        /// Handler for the DisplayAfterTimer.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        private void DisplayAfterTimerElapsed(object sender, EventArgs e)
        {
            _displayAfterTimer.Stop();
            IsContentVisible = true;
            ChangeVisualState(true);
        }

        /// <summary>
        /// Changes the control's visual state(s).
        /// </summary>
        /// <param name="useTransitions">True if state transitions should be used.</param>
        protected virtual void ChangeVisualState(bool useTransitions)
        {
            VisualStateManager.GoToState(this, IsBusy ? VisualStates.StateBusy : VisualStates.StateIdle, useTransitions);
            VisualStateManager.GoToState(this, IsContentVisible ? VisualStates.StateVisible : VisualStates.StateHidden, useTransitions);
        }

        /// <summary>
        /// Gets or sets a value indicating whether the busy indicator should show.
        /// </summary>
        public bool IsBusy
        {
            get { return (bool)GetValue(IsBusyProperty); }
            set { SetValue(IsBusyProperty, value); }
        }

        /// <summary>
        /// Identifies the IsBusy dependency property.
        /// </summary>
        public static readonly DependencyProperty IsBusyProperty = DependencyProperty.Register(
            "IsBusy",
            typeof(bool),
            typeof(BusyIndicator),
            new PropertyMetadata(false, new PropertyChangedCallback(OnIsBusyChanged)));

        /// <summary>
        /// IsBusyProperty property changed handler.
        /// </summary>
        /// <param name="d">BusyIndicator that changed its IsBusy.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnIsBusyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((BusyIndicator)d).OnIsBusyChanged(e);
        }

        /// <summary>
        /// IsBusyProperty property changed handler.
        /// </summary>
        /// <param name="e">Event arguments.</param>
        protected virtual void OnIsBusyChanged(DependencyPropertyChangedEventArgs e)
        {
            if (IsBusy)
            {
                if (DisplayAfter.Equals(TimeSpan.Zero))
                {
                    // Go visible now
                    IsContentVisible = true;
                }
                else
                {
                    // Set a timer to go visible
                    _displayAfterTimer.Interval = DisplayAfter;
                    _displayAfterTimer.Start();
                }
            }
            else
            {
                // No longer visible
                _displayAfterTimer.Stop();
                IsContentVisible = false;
            }
            ChangeVisualState(true);
        }

        /// <summary>
        /// Gets or sets a value indicating the busy content to display to the user.
        /// </summary>
        public object BusyContent
        {
            get { return (object)GetValue(BusyContentProperty); }
            set { SetValue(BusyContentProperty, value); }
        }

        /// <summary>
        /// Identifies the BusyContent dependency property.
        /// </summary>
        public static readonly DependencyProperty BusyContentProperty = DependencyProperty.Register(
            "BusyContent",
            typeof(object),
            typeof(BusyIndicator),
            new PropertyMetadata(null));

        /// <summary>
        /// Gets or sets a value indicating the template to use for displaying the busy content to the user.
        /// </summary>
        public DataTemplate BusyContentTemplate
        {
            get { return (DataTemplate)GetValue(BusyContentTemplateProperty); }
            set { SetValue(BusyContentTemplateProperty, value); }
        }

        /// <summary>
        /// Identifies the BusyTemplate dependency property.
        /// </summary>
        public static readonly DependencyProperty BusyContentTemplateProperty = DependencyProperty.Register(
            "BusyContentTemplate",
            typeof(DataTemplate),
            typeof(BusyIndicator),
            new PropertyMetadata(null));

        /// <summary>
        /// Gets or sets a value indicating how long to delay before displaying the busy content.
        /// </summary>
        public TimeSpan DisplayAfter
        {
            get { return (TimeSpan)GetValue(DisplayAfterProperty); }
            set { SetValue(DisplayAfterProperty, value); }
        }

        /// <summary>
        /// Identifies the DisplayAfter dependency property.
        /// </summary>
        public static readonly DependencyProperty DisplayAfterProperty = DependencyProperty.Register(
            "DisplayAfter",
            typeof(TimeSpan),
            typeof(BusyIndicator),
            new PropertyMetadata(TimeSpan.FromSeconds(0.1)));

        /// <summary>
        /// Gets or sets a value indicating the style to use for the overlay.
        /// </summary>
        public Style OverlayStyle
        {
            get { return (Style)GetValue(OverlayStyleProperty); }
            set { SetValue(OverlayStyleProperty, value); }
        }

        /// <summary>
        /// Identifies the OverlayStyle dependency property.
        /// </summary>
        public static readonly DependencyProperty OverlayStyleProperty = DependencyProperty.Register(
            "OverlayStyle",
            typeof(Style),
            typeof(BusyIndicator),
            new PropertyMetadata(null));

        /// <summary>
        /// Gets or sets a value indicating the style to use for the progress bar.
        /// </summary>
        public Style ProgressBarStyle
        {
            get { return (Style)GetValue(ProgressBarStyleProperty); }
            set { SetValue(ProgressBarStyleProperty, value); }
        }

        /// <summary>
        /// Identifies the ProgressBarStyle dependency property.
        /// </summary>
        public static readonly DependencyProperty ProgressBarStyleProperty = DependencyProperty.Register(
            "ProgressBarStyle",
            typeof(Style),
            typeof(BusyIndicator),
            new PropertyMetadata(null));
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Product Manager Outcoder
United States United States
Katka has several years of experience working in software development in the areas of market research and e-commerce. She has wide ranging experience in developing Java, ASP.Net MVC, ASP.Net, WPF, Silverlight, and Windows Phone applications.

Company: Outcoder.com
Group: XAML Experts
Proud co-creator of: Surfy browser, Airlock Browser

Comments and Discussions