European Silverlight 4 & Silverlight 5 Hosting BLOG

BLOG about Silverlight 5 Hosting and Its Techologies - Dedicated to European Windows Hosting Customer

European Silverlight 4.0 Hosting - Amsterdam :: How To Control Playback of Media Using a MediaElement of Silverlight?

clock December 10, 2013 06:02 by author Patrick

We can integrate media into our Silverlight pages and WPF UserControls. The MediaElement object provides several media-specific properties. The following list describes the commonly used properties.

  •     AutoPlay: Specifies whether the MediaElement should begin playing automatically. The default value is True.
  •     IsMuted: Specifies whether the MediaElement is silenced. A value of True mutes the MediaElement. The default value is False.
  •     Stretch: Specifies how video is stretched to fill the MediaElement object. Possible values are None, Uniform, UniformToFill, and Fill. The default is Fill.
  •     Volume: Specifies the volume of the MediaElement object’s audio as a value from 0 to 1, with 1 being the loudest. The default value is 0.5.

In addition to its media-specific properties, MediaElement also has all the properties of a UIElement, such as Opacity and Clip.


Controlling Media Playback

You can control media playback by using the Play, Pause, and Stop methods of a MediaElement object.

        xmlns:x="" Loaded="CanvasLoaded">
    <MediaElement x:Name="MyMedia" Stretch="Uniform"
        Source="/images/Silverlight_Small.wmv" Height="200" Width="200" />
  <Canvas x:Name="ButtonPanel">
      <Canvas Background="Red" Canvas.Left="10" Canvas.Top="185" Height="25" Width="50"
        MouseLeftButtonDown="StopMedia" Cursor="Hand">
        <Rectangle Height="30" Width="40" Canvas.Left="10" />
        <TextBlock Text="Stop" Canvas.Left="10" Foreground="Yellow" />
       <Canvas Background="Green" Canvas.Left="70" Canvas.Top="185" Height="25" Width="50"
        MouseLeftButtonDown="PlayMedia" Cursor="Hand">
        <Rectangle Height="30" Width="40" Canvas.Left="10" />
        <TextBlock Text="Play" Canvas.Left="10" Foreground="Yellow" />
       <Canvas Background="Blue" Canvas.Left="130" Canvas.Top="185" Height="25" Width="60"
        MouseLeftButtonDown="PauseMedia" Cursor="Hand">
        <Rectangle Height="30" Width="40" Canvas.Left="10" />
        <TextBlock Text="Pause" Canvas.Left="10" Foreground="Yellow" />
       <Canvas Background="Black" Canvas.Left="10" Canvas.Top="215" Height="25" Width="180"
        MouseLeftButtonDown="ToggleFullScreen" Cursor="Hand">
        <Rectangle Height="30" Width="40" Canvas.Left="10" />
        <TextBlock Text="Full Screen" Canvas.Left="55" Foreground="Yellow" />

// --------- JavaScript Code to control the Media object -------------
// Fires when Canvas is loaded
function CanvasLoaded(sender, args)
    var canvas = sender.getHost();
    canvas.content.onfullScreenChange = onFullScreenChanged;                            
// Fires when Full screen is changed
function onFullScreenChanged(sender, args)
    var canvas = sender.getHost();
    var buttonPanel = sender.findName("ButtonPanel");
    // Change the opacity of the button panel so that in the full screen it disappears and in normal screen it appears
    if (canvas.content.fullScreen == true)
        buttonPanel.opacity = 0;
        buttonPanel.opacity = 1;
    // change the media object height and width to the canvas height and width
    var media = sender.findName("MyMedia");
    media.width = canvas.content.actualWidth;
    media.height = canvas.content.actualHeight;
//Fires when Full Screen button is clicked
function ToggleFullScreen(sender, args)
    var canvas = sender.getHost();
    canvas.content.fullScreen = !canvas.content.fullScreen;
// Fires when Stop button is clicked
function StopMedia(sender, args)
// Fires when Play button is clicked
function PlayMedia(sender, args)
// Fires when Pause button is clicked
function PauseMedia(sender, args)

Hope this helps!!

European Silverlight 5 Hosting - Amsterdam :: How to Convert Silverlight 4 to Silverlight 5

clock August 9, 2013 08:09 by author Scott

When we open Silverlight 4 application in Silverlight 5 we get following errors

1) error  : Unable to read the project file 'Silverlight4App.csproj'.

2) Silverlight4App.csproj(137,3): The imported project "C:\Program Files\MSBuild\Microsoft\Silverlight\v4.0\Microsoft.Silverlight.CSharp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

This error occurs as the application was earlier built using Silverlight-4 Reference. So while opening this in Silverlight-5, the Visual studio looks for the Silverlight 5 reference files but it cannot find it.

To resolve this error you will have to follow following steps:

1) Open the project in Visual studio.

2) Go to solution explorer

3) Right click on the project that is not loaded and click on edit the CSPROJ file

4) And then change the Target Frame Work version to 5.0

5) Save and close this file and again right click on the project which is not loaded and click on Reload project.

6) Now the project will be reloaded successfully.

By following above steps your Silverlight 4 application will be converted to Silverlight 5 application.

If in case you again want to go back to Silverlight 4 then just repeat the above steps and set the Target Framework version to “v4.0”.

Hope this helps!!

About is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.

Tag cloud

Sign in