European Silverlight Hosting BLOG

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

Silverlight 6 Hosting - HostForLIFE.eu :: How to Control Playback in A Video

clock September 17, 2015 11:07 by author Rebecca

Using videos in a Silverlight based application is a very exciting feature. In this article, we will learn how we can control the playback of movie using some coding in code-behind. Let's see how!

Dealing with Automatic Start

By default videos automaticall get started when we run the project, it is distracting feature from the users point of view. To change auto start false, select the video on stage and in properties uncheck the 'AutoPlay' option.

Dealing with Endless Playback

By default, when the video reaches the end then it stops and does not start again. To change such a setting follow the steps:

1. Select the video on stage

2. In Properties, switch the mode from 'Properties' to 'Events'.

3. In the Event list, point to 'MediaEnded' label and type the event handler name (I will be using md_ended_eve) and then press tab to apply it and it automatically switches you to code-behind with a new event.

4. Now type the following code inside event handler:

(intro_wmv).Stop();
(intro_wmv).Play();

In above code 'intro_wmv' is my media fine name.

5. Now test the application.

XAML Code
<Grid
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          x:Class="SilverlightApplication1.MainPage"
          Width="640" Height="480">
          <MediaElement x:Name="intro_wmv"
          Margin="54,64,104,60"
          Source="/intro.wmv"
          Stretch="Fill"
          MediaEnded="md_ended_eve" AutoPlay="False"/>
</Grid>

XAML.CS Code
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApplication1
{
       public partial class MainPage : Grid
       {
              public MainPage()
              {
                     // Required to initialize variables
                     InitializeComponent();
              }
              private void md_ended_eve(object sender, System.Windows.RoutedEventArgs e)
              {
                     // TODO: Add event handler implementation here.
                     (intro_wmv).Stop();
                     (intro_wmv).Play();
              }
       }
}

Control Video Playback by Pause and Play

By default in Silverlight video plays and we can't control it by pausing and playing. But by writing some lines in code-behind we can control this playback. For this we have to create the event as we saw in above example. Let's follow the steps:

1. Open the event explorer by switching the property (look above image).

2. Type the event name in 'MouseLeftButtonDown', I will be using here 'pause_start_evn' and press tab to switch in event handler mode.

3. In the appeared event type the following code:

private bool IsPaused=true;
private void pause_start_evn(object sender, System.Windows.Input.MouseButtonEventArgs e)
              {
                     // TODO: Add event handler implementation here.
                     if(IsPaused)
                     {
                           (intro_wmv as MediaElement).Play();
                           IsPaused=false;
                     }
                     else
                     {
                           (intro_wmv as MediaElement).Pause();
                           IsPaused=true;
                     }
   }

4. Now test the application and check by right mouse click on video surface.

XAML Code
<Grid
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          x:Class="SilverlightApplication1.MainPage"
          Width="640" Height="480">
          <MediaElement x:Name="intro_wmv"
          Margin="54,64,104,60"
          Source="/intro.wmv"
          Stretch="Fill"
          MediaEnded="md_ended_eve"
          MouseLeftButtonDown="pause_start_evn"/>
</Grid>

XAXM.CS Code

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication1
{
       public partial class MainPage : Grid
       {
              public MainPage()
              {
                     // Required to initialize variables
                     InitializeComponent();
              }

              private void md_ended_eve(object sender, System.Windows.RoutedEventArgs e)
              {
                     // TODO: Add event handler implementation here.
                     (intro_wmv).Stop();
                     (intro_wmv).Play();
              }
              private bool IsPaused=true;
              private void pause_start_evn(object sender, System.Windows.Input.MouseButtonEventArgs e)
              {
                     // TODO: Add event handler implementation here.
                     if(IsPaused)
                     {
                           (intro_wmv as MediaElement).Play();
                           IsPaused=false;
                     }
                     else
                     {
                           (intro_wmv as MediaElement).Pause();
                           IsPaused=true;
                     }
              }
       }
}

Now, that's all about the controlling of video playback in a Silverlight based application. Happy coding!

HostForLIFE.eu Silverlight 6 Hosting
HostForLIFE.eu 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 customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



Silverlight 6 Hosting - HostForLIFE.eu :: How to Use ASP.NET to Create Silverlight Clock Apps

clock September 10, 2015 11:37 by author Rebecca

In this post, we will learn how to create Analog Clock completely from code behind using .NET Silverlight.

Step 1

Create a new project in Visual Studio and select "Silverlight Application".

Step 2

Open MainPage.xaml and add the following code:


    <UserControl x:Class="SilverlightAnalogClock.MainPage" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        mc:Ignorable="d" 
        d:DesignHeight="300" d:DesignWidth="400"> 
     
        <Grid x:Name="LayoutRoot" Background="White"> 
            
        </Grid> 
    </UserControl> 

Step 3

Open MainPage.xaml.cs and add the following code:

    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.Media.Imaging; 
    using System.Windows.Shapes; 
     
    namespace SilverlightAnalogClock 
    { 
        public partial class MainPage : UserControl 
        { 
     
            public Canvas ClockArea = null; 
            public Rectangle secondHand = null; 
            public Rectangle minuteHand = null; 
            public Rectangle hourHand = null; 
     
            public RotateTransform secondHandRotate = null; 
            public RotateTransform minuteHandRotate = null; 
            public RotateTransform hourHandRotate = null; 
     
            public Ellipse outerCircle = null; 
     
            public Point centerPoint; 
            public double HEIGHT  = 0; 
            public double WIDTH  = 0; 
            public double RADIUS = 0; 
     
            public MainPage() 
            { 
                InitializeComponent(); 
     
                ClockArea = new Canvas() 
                { 
     
                    Width = 300, 
                    Height = 300, 
                    HorizontalAlignment = HorizontalAlignment.Left, 
                    VerticalAlignment = VerticalAlignment.Top 
     
                }; 
     
                ClockArea.SetValue(Grid.RowProperty, 0); 
                ClockArea.SetValue(Grid.ColumnProperty, 0); 
                ClockArea.Margin = new Thickness(0, 0, 0, 0); 
                this.LayoutRoot.Children.Add(ClockArea); 
     
                WIDTH = ClockArea.Width; 
                HEIGHT = ClockArea.Height; 
                centerPoint.X = (WIDTH/2); 
                centerPoint.Y = (HEIGHT/2); 
                      
                RADIUS = 400; 
                DrawClockFace(); 
     
                Point TOPPOINT = new Point(0, 0); 
     
                DrawMinuteHand(); 
                DrawSecondHand(); 
                DrawHourHand(); 
                DrawCenterCircle(); 
     
     
                //Start the Clock 
                ClockStart(); 
                 
     
            } 
     
            public void ClockStart() 
            { 
                // Create and Start the Thread Timer 
                System.Windows.Threading.DispatcherTimer clockTimer = new System.Windows.Threading.DispatcherTimer(); 
                clockTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000); 
                clockTimer.Tick += new EventHandler(Clock_Tick); 
                clockTimer.Start(); 
            } 
     
            // Get and Set the Angles of Each Hand at every Clock Ticks 
            public void Clock_Tick(object o, EventArgs sender) 
            { 
                double hourRotateValue = Convert.ToDouble(DateTime.Now.Hour.ToString()); 
                double minuteRotateValue = Convert.ToDouble(DateTime.Now.Minute.ToString()); 
                double secondRotateValue = Convert.ToDouble(DateTime.Now.Second.ToString()); 
                hourRotateValue = (hourRotateValue + minuteRotateValue / 60) * 30; 
                minuteRotateValue = (minuteRotateValue + secondRotateValue / 60) * 6; 
                secondRotateValue = Convert.ToDouble(DateTime.Now.Second.ToString()) * 6; 
                minuteHandRotate.Angle = minuteRotateValue; 
                hourHandRotate.Angle = hourRotateValue; 
                secondHandRotate.Angle = secondRotateValue; 
            } 
     
            // Draw Center Circle 
            public void DrawCenterCircle() 
            {             
                Ellipse centerCircle = new Ellipse() 
                { 
     
                    Width = 10, 
                    Height = 10, 
                    Stroke = new SolidColorBrush(Colors.Red), 
                    Fill = new SolidColorBrush(Colors.Red), 
                    HorizontalAlignment = HorizontalAlignment.Center, 
                    VerticalAlignment = VerticalAlignment.Center 
     
                }; 
     
                centerCircle.SetValue(Grid.RowProperty, 0); 
                centerCircle.SetValue(Grid.ColumnProperty, 0); 
                Canvas.SetLeft(centerCircle, (WIDTH / 2) - (centerCircle.Width / 2)); 
                Canvas.SetTop(centerCircle, (HEIGHT / 2) - (centerCircle.Height / 2)); 
                ClockArea.Children.Add(centerCircle); 
            } 
     
            // Draw Clock Face 
            public void DrawClockFace() 
            { 
                         
                int smallCircle = 5; 
     
                Color c = Colors.Blue; 
                int p = 0; 
     
                // Draw Shadow of Outer Circle 
                Ellipse outerCircleShadow = new Ellipse() 
                { 
                    Width = (WIDTH), 
                    Height = (WIDTH), 
                    Stroke = new SolidColorBrush(Colors.Gray), 
                    StrokeThickness = 5, 
                    HorizontalAlignment = HorizontalAlignment.Center, 
                    VerticalAlignment = VerticalAlignment.Center 
                     
                }; 
                
                outerCircleShadow.SetValue(Grid.RowProperty, 0); 
                outerCircleShadow.SetValue(Grid.ColumnProperty, 0); 
                Canvas.SetLeft(outerCircleShadow, (WIDTH / 2) - (outerCircleShadow.Width / 2) + 6.5); 
                Canvas.SetTop(outerCircleShadow, (HEIGHT / 2) - (outerCircleShadow.Height / 2) + 6.5); 
                ClockArea.Children.Add(outerCircleShadow); 
                
                //  Draw Outer Circle 
                outerCircle = new Ellipse() 
                { 
                    Width = (WIDTH ), 
                    Height = (WIDTH), 
                    Stroke = new SolidColorBrush(Colors.Black), 
                    StrokeThickness = 5, 
                    HorizontalAlignment = HorizontalAlignment.Center, 
                    VerticalAlignment = VerticalAlignment.Center 
                };             
                outerCircle.SetValue(Grid.RowProperty, 0); 
                outerCircle.SetValue(Grid.ColumnProperty, 0); 
                Canvas.SetLeft(outerCircle, (WIDTH / 2) - (outerCircle.Width / 2) + 4.5); 
                Canvas.SetTop(outerCircle, (HEIGHT / 2) - (outerCircle.Height / 2) + 4.5); 
                ClockArea.Children.Add(outerCircle); 
     
     
                outerCircle.Fill = new LinearGradientBrush() 
                    { 
                        EndPoint = new Point(1, 0), 
                        GradientStops = new GradientStopCollection() 
                        { 
                                new GradientStop() { Color = Colors.White, Offset = 0 }, 
                                new GradientStop() { Color = Colors.Gray, Offset = 0.5 }, 
                                 new GradientStop() { Color = Colors.White, Offset = 1 } 
                        } 
                    }; 
     
                int clockDigits = 3; 
                double rad = (WIDTH/2) - 10.0f; 
                // 60 Innner Dots as Small Circle 
                for (double i = 0.0; i < 360.0; i += 6)  
                {  
     
                double angle = i * System.Math.PI / 180; 
     
                int x = (int)(centerPoint.X + rad * System.Math.Cos(angle)); 
                int y = (int)(centerPoint.Y + rad * System.Math.Sin(angle)); 
     
                if (p % 5 == 0) 
                { 
                    smallCircle = 10; 
                    c = Colors.Orange;                 
                } 
                else 
                { 
                    smallCircle = 5; 
                    c = Colors.Blue; 
                } 
                if (p % 15 == 0) 
                { 
                    TextBlock tb = new TextBlock(); 
                    tb.Text = clockDigits.ToString(); 
                    tb.FontSize = 24; 
                     
                    tb.SetValue(Grid.RowProperty, 0); 
                    tb.SetValue(Grid.ColumnProperty, 0); 
                    Canvas.SetLeft(tb, x ); 
                    Canvas.SetTop(tb, y); 
                    if (clockDigits == 3) 
                    { 
                        Canvas.SetLeft(tb, x - 20); 
                        Canvas.SetTop(tb, y - 10); 
                    } 
                    if (clockDigits == 6) 
                    { 
                        Canvas.SetLeft(tb, x); 
                        Canvas.SetTop(tb, y - 30); 
                    } 
                    if (clockDigits == 9) 
                    { 
                        Canvas.SetLeft(tb, x + 15); 
                        Canvas.SetTop(tb, y - 10); 
                    } 
                    if (clockDigits == 12) 
                    { 
                        Canvas.SetLeft(tb, x - 10); 
                        Canvas.SetTop(tb, y + 5 ); 
                    }  
                   
                     
                    ClockArea.Children.Add(tb); 
                    clockDigits = clockDigits + 3; 
                } 
     
                p++; 
                
                            Ellipse innerPoints = new Ellipse() 
                            { 
                                Width = smallCircle, 
                                Height = smallCircle, 
                                Stroke = new SolidColorBrush(c), 
                                Fill = new SolidColorBrush(c), 
                                HorizontalAlignment = HorizontalAlignment.Center, 
                                VerticalAlignment = VerticalAlignment.Center 
                            }; 
                            innerPoints.SetValue(Grid.RowProperty, 0); 
                            innerPoints.SetValue(Grid.ColumnProperty, 0); 
                            Canvas.SetLeft(innerPoints, x); 
                            Canvas.SetTop(innerPoints, y); 
                            ClockArea.Children.Add(innerPoints); 
     
                } 
     
                 
            } 
            // Draw the Second Hand 
            public void DrawSecondHand() 
            { 
     
                double handLength = (HEIGHT / 2) - 20; 
                secondHand = new Rectangle() 
                { 
                    Width = 1, 
                    Height = handLength, 
                    Stroke = new SolidColorBrush(Colors.Red), 
                    Fill = new SolidColorBrush(Colors.Red), 
                    HorizontalAlignment = HorizontalAlignment.Center, 
                    VerticalAlignment = VerticalAlignment.Center 
                }; 
                 
                secondHand.SetValue(Grid.RowProperty, 0); 
                secondHand.SetValue(Grid.ColumnProperty, 0); 
                //Add Rotate Transformation 
                secondHandRotate = new RotateTransform(); 
                secondHandRotate.Angle = 0; 
                //Set Center for Rotation 
                secondHandRotate.CenterX = Canvas.GetLeft(secondHand); 
                secondHandRotate.CenterY = secondHand.Height; 
                secondHand.RenderTransform = secondHandRotate; 
                //Set Initial Position of Hand 
                Canvas.SetTop(secondHand, centerPoint.Y - handLength); 
                Canvas.SetLeft(secondHand, WIDTH/2);            
                ClockArea.Children.Add(secondHand); 
                
            } 
     
            public void DrawMinuteHand() 
            { 
                double handLength = (HEIGHT / 2) - 50; 
                minuteHand = new Rectangle() 
                { 
                    Width = 4, 
                    Height = handLength, 
                    Stroke = new SolidColorBrush(Colors.Black), 
                    Fill = new SolidColorBrush(Colors.Black), 
                    HorizontalAlignment = HorizontalAlignment.Center, 
                    VerticalAlignment = VerticalAlignment.Center 
                }; 
     
                minuteHand.SetValue(Grid.RowProperty, 0); 
                minuteHand.SetValue(Grid.ColumnProperty, 0); 
     
                minuteHandRotate = new RotateTransform(); 
                minuteHandRotate.Angle = 0; 
                minuteHandRotate.CenterX = Canvas.GetLeft(minuteHand); 
                minuteHandRotate.CenterY = minuteHand.Height; 
                minuteHand.RenderTransform = minuteHandRotate; 
                Canvas.SetTop(minuteHand, centerPoint.Y - handLength); 
                Canvas.SetLeft(minuteHand, WIDTH / 2); 
                ClockArea.Children.Add(minuteHand); 
     
            } 
            public void DrawHourHand() 
            { 
                double handLength = (HEIGHT / 2) - 80; 
                hourHand = new Rectangle() 
                { 
                    Width = 4, 
                    Height = handLength, 
                    Stroke = new SolidColorBrush(Colors.Black), 
                    Fill = new SolidColorBrush(Colors.Black), 
                    HorizontalAlignment = HorizontalAlignment.Center, 
                    VerticalAlignment = VerticalAlignment.Center 
                }; 
     
                hourHand.SetValue(Grid.RowProperty, 0); 
                hourHand.SetValue(Grid.ColumnProperty, 0); 
     
                hourHandRotate = new RotateTransform(); 
                hourHandRotate.Angle = 0; 
                hourHandRotate.CenterX = Canvas.GetLeft(hourHand); 
                hourHandRotate.CenterY = hourHand.Height; 
                hourHand.RenderTransform = hourHandRotate; 
                Canvas.SetTop(hourHand, centerPoint.Y - handLength); 
                Canvas.SetLeft(hourHand, WIDTH / 2);    
                ClockArea.Children.Add(hourHand); 
     
            } 
     
        } 
    } 


The Output

Now execute and you will get a fully drawn Silverlight Analog Clock.


HostForLIFE.eu Silverlight 6 Hosting
HostForLIFE.eu 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 customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



HostForLIFE.eu Proudly Launches ASP.NET 4.6 Hosting

clock September 7, 2015 12:36 by author Peter

HostForLIFE.eu was established to cater to an underserved market in the hosting industry; web hosting for customers who want excellent service. HostForLIFE.eu – a cheap, constant uptime, excellent customer service, quality, and also reliable hosting provider in advanced Windows and ASP.NET technology. HostForLIFE.eu proudly announces the availability of the ASP.NET 4.6 hosting in their entire servers environment.

http://hostforlife.eu/img/logo_aspnet1.png

ASP.NET is Microsoft's dynamic website technology, enabling developers to create data-driven websites using the .NET platform and the latest version is 5 with lots of awesome features. ASP.NET 4.6 is a lean .NET stack for building modern web apps. Microsoft built it from the ground up to provide an optimized development framework for apps that are either deployed to the cloud or run on-premises. It consists of modular components with minimal overhead.

According to Microsoft officials, With the .NET Framework 4.6, you'll enjoy better performance with the new 64-bit "RyuJIT" JIT and high DPI support for WPF and Windows Forms. ASP.NET provides HTTP/2 support when running on Windows 10 and has more async task-returning APIs. There are also major updates in Visual Studio 2015 for .NET developers, many of which are built on top of the new Roslyn compiler framework. The .NET languages -- C# 6, F# 4, VB 14 -- have been updated, too.There are many great features in the .NET Framework 4.6. Some of these features, like RyuJIT and the latest GC updates, can provide improvements by just installing the .NET Framework 4.6.

HostForLIFE.eu hosts its servers in top class data centers that is located in Amsterdam (NL), London (UK), Paris (FR), Frankfurt(DE) and Seattle (US) to guarantee 99.9% network uptime. All data center feature redundancies in network connectivity, power, HVAC, security, and fire suppression. All hosting plans from HostForLIFE.eu include 24×7 support and 30 days money back guarantee. The customers can start hosting their ASP.NET 4.6 site on their environment from as just low €3.00/month only.

HostForLIFE.eu is a popular online ASP.NET based hosting service provider catering to those people who face such issues. The company has managed to build a strong client base in a very short period of time. It is known for offering ultra-fast, fully-managed and secured services in the competitive market.

HostForLIFE.eu offers the latest European ASP.NET 4.6 hosting installation to all their new and existing customers. The customers can simply deploy their ASP.NET 4.6 website via their world-class Control Panel or conventional FTP tool. HostForLIFE.eu is happy to be offering the most up to date Microsoft services and always had a great appreciation for the products that Microsoft offers.

Further information and the full range of features ASP.NET 4.6 Hosting can be viewed here http://hostforlife.eu/European-ASPNET-46-Hosting



About HostForLIFE

HostForLIFE 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 2019 Hosting, ASP.NET 5 Hosting, ASP.NET MVC 6 Hosting and SQL 2019 Hosting.


Tag cloud

Sign in