European Silverlight Hosting BLOG

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

European Silverlight 5 Hosting - Amsterdam :: Silverlight Sorting and Grouping Feature

clock June 28, 2013 07:56 by author Scott

Using Silverlight and XAML, you can bind to a collection of data. Once that is done, you can then sort, filter, or group the data using a collection view. A collection view is similar to a layer on a binding source collection. It enables you to navigate and display the source collection based on queries to sort, filter, and group data, without having to change the underlying source collection itself. If a source collection implements the INotifyCollectionChanged interface, the changes raised by the CollectionChanged event are transmitted to the views. A single source collection can have multiple views associated with it.

 

I will show brief tutorial about sorting and grouping functionally through the PagedCollectionView class. Consider an example that demonstrates how to sort and group bound data in a collection using an
PagedCollectionView object.

Create a Silverlight application named CollectionsDemo.

Add the following markup to MainPage.xaml.

<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    x:Class="CollectionsDemo.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"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=System.Windows"
xmlns:dat="clr-namespace:System.Windows.Data;assembly=System.Windows"
xmlns:local="clr-namespace:CollectionsDemo"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400"

<Grid x:Name="LayoutRoot">
    <sdk:DataGrid Name="dgridMovies" ItemsSource="{Binding}" >
            <sdk:DataGrid.RowGroupHeaderStyles>
                <Style TargetType="sdk:DataGridRowGroupHeader">
                    <Setter Property="PropertyNameVisibility" Value="Collapsed" />
                    <Setter Property="Background" Value="PaleGreen"/>
                    <Setter Property="SublevelIndent" Value="25" />
                </Style>
            </sdk:DataGrid.RowGroupHeaderStyles>
        </sdk:DataGrid>
</Grid>
</UserControl>

The above markup creates a DataGrid and sets its ItemsSource property. The markup also sets style for the DataGrid rows.

Add the following code to MainPage.xaml.cs to create the Movies and Movie classes:

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;
using System.Collections.ObjectModel;
using System.Windows.Data;
using System.ComponentModel;

namespace CollectionsDemo
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            Movies movies = new Movies();
            InitializeComponent();

            // For sorting
            PagedCollectionView pg = new PagedCollectionView(movies);
            pg.SortDescriptions.Add(new SortDescription("Title", ListSortDirection.Ascending));
            dgridMovies.DataContext = pg;

            // For grouping
            pg.GroupDescriptions.Add(new PropertyGroupDescription("Year"));
            dgridMovies.DataContext = pg;
        }
    }

    // Represents a collection of movies
    public class Movies : ObservableCollection<Movie>
    {
        public Movies()
            : base()
        {
         Add(new Movie() { Title = "Sherlock Holmes - Game of Shadows", Year = "2011" });
         Add(new Movie() { Title = "ParaNormal Activity", Year = "2010" });
         Add(new Movie() { Title = "Michael Clayton", Year = "2010" });
         Add(new Movie() { Title = "A Separation", Year = "2011" });
         Add(new Movie() { Title = "Lost", Year = "2009" });
        }
    }

// Represents a Movie entity having two properties, Title and Year
    public class Movie
    {
        public string Title { get; set; }
        public string Year { get; set; }
    }
}

You will first create a PropertyGroupDescription object and pass the name of the property based on which sorting or grouping will take place. Then, add the PropertyGroupDescription to the SortDescriptions or GroupDescriptions collection of PagedCollectionView depending on which operation is to be performed.

These actions are done using the above code.

On executing, the output will be similar to Figure below. As you can see, the movie details are grouped by year and sorted according to title.


 



European Silverlight Hosting - Amsterdam :: Silverlight Watermark TextBox Behavior

clock April 29, 2013 10:48 by author Scott

Maybe there is a working solution for this already out there, but I created my own Silverlight Behavior for a basic TextBox Watermark which might be useful.

I wanted to use it like this in my XAML (look at the behaviors tag):

<TextBlock Margin="5">Watermarked textbox:</TextBlock>
<TextBox Margin="5">
    <Interactivity:Interaction.Behaviors>
        <local:Watermark Text="Watermark" Foreground="LightGray" />
    </Interactivity:Interaction.Behaviors>
</TextBox>

The result should be something like this:

To create a Behavior for Silverlight, you must get hold of the System.Windows.Interactivity assembly which ships with Expression Blend. In my system it’s located at:

c:\Program Files (x86)\Microsoft SDKs\Expression\Blend\Silverlight\v4.0\Libraries\System.Windows.Interactivity.dll

And the code for the Behavior:

public class Watermark : Behavior<TextBox>
{
    private bool _hasWatermark;
    private Brush _textBoxForeground;
 
    public String Text { get; set; }
    public Brush Foreground { get; set; }
 
    protected override void OnAttached()
    {
        _textBoxForeground = AssociatedObject.Foreground;
 
        base.OnAttached();
        if (Text != null)
            SetWatermarkText();
        AssociatedObject.GotFocus += GotFocus;
        AssociatedObject.LostFocus += LostFocus;
    }
 
    private void LostFocus(object sender, RoutedEventArgs e)
    {
        if (AssociatedObject.Text.Length == 0)
            if (Text != null)
                SetWatermarkText();
    }
 
    private void GotFocus(object sender, RoutedEventArgs e)
    {
        if (_hasWatermark)
            RemoveWatermarkText();
    }
 
    private void RemoveWatermarkText()
    {
        AssociatedObject.Foreground = _textBoxForeground;
        AssociatedObject.Text = "";
        _hasWatermark = false;
    }
 
    private void SetWatermarkText()
    {
        AssociatedObject.Foreground = Foreground;
        AssociatedObject.Text = Text;
        _hasWatermark = true;
    }
 
    protected override void OnDetaching()
    {
        base.OnDetaching();
        AssociatedObject.GotFocus -= GotFocus;
        AssociatedObject.LostFocus -= LostFocus;
    }
}

Like so many Watermark-solutions out there I’m hooking into the GotFocus/LostFocus events and to the work there. Works for me.

 



European Silverlight Hosting - Amsterdam :: Silverlight BlurEffect Example

clock March 11, 2013 07:12 by author Scott

In this article we will be seeing how to create Silverlight BlurEffect using Visual studio 2010.

Pixel shader effects in Silverlight allows you to add effects, such as gray scale, red eye removal, pixel brightness, and shadows, to rendered objects. There are two types of Pixel Shader effects in Silverlight. They are BlurEffect and DropShadowEffect. In this we will be seeing about BlurEffect and its properties.

Namespace: System.Windows.Media. Effects

Assembly: System.Windows

BlurEffect:

BlurEffect is used to represent an effect that we can apply to an object that simulates looking at the object through an out-of-focus lens. It is defined by the Radius property.

Radius:

This property is used to specify the amount of blur to apply to an object.

Without BlurEffect:

<Canvas Height="200" Width="200" Background="white">
        <Rectangle Height="50" Width="50" Fill="Orange" Canvas.Left="25" Canvas.Top="75"></Rectangle>
        <Rectangle Height="50" Width="50" Fill="White" Canvas.Left="75" Canvas.Top="75"></Rectangle>
        <Rectangle Height="50" Width="50" Fill="Green" Canvas.Left="125" Canvas.Top="75"></Rectangle>
</Canvas>

With BlurEffect:

<Canvas Height="200" Width="200" Background="white">
        <Canvas.Effect>
            <BlurEffect Radius="120"></BlurEffect>
        </Canvas.Effect>   
        <Rectangle Height="50" Width="50" Fill="Orange" Canvas.Left="25" Canvas.Top="75"></Rectangle>
        <Rectangle Height="50" Width="50" Fill="White" Canvas.Left="75" Canvas.Top="75"></Rectangle>
        <Rectangle Height="50" Width="50" Fill="Green" Canvas.Left="125" Canvas.Top="75"></Rectangle>
</Canvas>

Steps Involved:

Creating a Silverlight Application:

-
Open Visual Studio 2010. 
-
Go to File => New => Project. 
-
Select Silverlight from the Installed templates and choose the Silverlight Application template. 
-
Enter the Name and choose the location. 
-
Click OK. 
-
In the New Silverlight Application wizard check the "Host the Silverlight Application in a new Web site". 
-
Click OK.

Creating the UI:

Open MainPage.xaml file and replace the code with the following.

<UserControl x:Class="SilverlightBlurEffect.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">
    <Canvas Height="200" Width="200" Background="white">
        <Canvas.Effect>
            <BlurEffect Radius="120"></BlurEffect>
        </Canvas.Effect>   
        <Rectangle Height="50" Width="50" Fill="Orange" Canvas.Left="25" Canvas.Top="75"></Rectangle>
        <Rectangle Height="50" Width="50" Fill="White" Canvas.Left="75" Canvas.Top="75"></Rectangle>
        <Rectangle Height="50" Width="50" Fill="Green" Canvas.Left="125" Canvas.Top="75"></Rectangle>
    </Canvas>
</UserControl>

To test it, please just build the solution and hit CTRL+F5

 



European Silverlight Hosting - Amsterdam :: Working with Isolated Storage in Silverlight

clock November 29, 2012 07:46 by author Scott

Isolated storage gives you access to a small segment of hard-disk space, with certain limitations. For example we don't know exactly where our files are being stored. We also can't read the files left by another Silverlight application or recorded for another user. In essence, isolated storage provides carefully restricted, tamperproof file access for applications that need to store permanent information in the local PC, so that information can be retrieved the next time the user runs the application.

How it works:

Isolated storage provides a virtual file system that lets you write data to a small, user-specific and application-specific slot of space. There's no way to know beforehand exactly where the data will be written, and the default space limit is a mere 1 MB (although you can request that the user grant you more).

Is it similar to browser Cookie?

  1. Essentially, isolated storage is the Silverlight equivalent of persistent cookies in an ordinary web page. It allows small bits of information to be stored in a dedicated location that has specific controls in place to prevent malicious attacks.
     
  2. Isolated storage is persistent–unlike the browser cache, it never expires, and it's not removed if the user chooses to explicitly delete temporary Internet files.
     
  3. Isolated storage isn't a good storage place for important documents, because they're never backed up, are easily deleted, and can be even more easily lost.
     
  4. Isolated storage is intended to be a limited-size storage location for data, not a handcrafted replacement for HTTP Caching.


Scope of Isolated Storage:


With isolated storage, a unique storage location is created for every combination of user and application. In other words, the same computer can have multiple isolated storage locations for the same application, assuming each one is for a different user. Similarly, the same user can have multiple isolated storage locations, one for each Silverlight application. Isolated storage isn't affected by browser, so a Windows user switching from Internet Explorer to Firefox will get the same isolated storage location in both browsers.

What all can we store in an Isolated Storage: Good choices include user-specific details, user preferences, and information about recent user actions. Isolated storage is also great temporary storage.

So now we are ready to create a application which will demonstrate how it works.

Step 1: Create a Silverlight Application project and name it IsolatedStorage.

Step 2: Now we will try to understand how to write data and read data from these storages Medias. We will also see if we want to increase the space on the handdisk; how can we do that as well.

So we created a simple xmal like this:

<Grid x:Name="LayoutRoot"  Margin="10"  Background="WhiteSmoke" Width="340" Height="200" HorizontalAlignment="Center" VerticalAlignment="Center">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>         

        </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" ></ColumnDefinition>
            <ColumnDefinition Width="Auto" ></ColumnDefinition>           

        </Grid.ColumnDefinitions>

            <TextBlock Text="Enter Your Name" Margin="3" Padding="5" HorizontalAlignment="Left" 
                       VerticalAlignment="Center" Grid.Row="0" Grid.Column="0">               
           
</TextBlock>

            <TextBox x:Name="txtname" Margin="3" Padding="5"
                        HorizontalAlignment="Left" VerticalAlignment="Center"
                        Grid.Row="0" Grid.Column="1" Height="30" Width="200" ></TextBox>          

            <Grid Grid.Column="1" Grid.Row="1"  Margin="5" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="50" ></RowDefinition>
                    <RowDefinition ></RowDefinition>
                    <RowDefinition ></RowDefinition>
            </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition ></ColumnDefinition>
                    <ColumnDefinition ></ColumnDefinition>
                </Grid.ColumnDefinitions>

            <Button x:Name="btnWrite"  Margin="5" Padding="5" Width="90" Height="30"
                    Content="Click to Write" HorizontalAlignment="Center" VerticalAlignment="Top"
                    Click="btnWrite_Click">
            </Button>

            <Button x:Name="btnRead"  Margin="5" Padding="5" Width="90" Height="30"
                    Content="Click to Read"
                    HorizontalAlignment="Center" VerticalAlignment="Top" Click="btnRead_Click"
                    Grid.Row="0" Grid.Column="1">
            </Button>

            <Button x:Name="btnSize"  Padding="5" Width="180" Height="30"
                    Content="Click to Increase Disk Storage Space"
                     HorizontalAlignment="Center" VerticalAlignment="Top"
                    Click="btnSize_Click" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
            </Button>

            <TextBlock x:Name="lblData" Margin="5"  HorizontalAlignment="Center" VerticalAlignment="Top"                       
                    Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"></TextBlock>

        </Grid>

Step 3: Now come to Code Behind and write handler for btnWrite_Click.

Also add this Isolated storage namespace.

using System.IO.IsolatedStorage;

private void btnWrite_Click(object sender, RoutedEventArgs e)
        {
            // Write to isolated storage.
            try
            {               
                //this gives you exactly what you want: an application-specific, user-specific
                //location where you can store data.

               IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();

                 //If we would have used
                //IsolatedStorageFile.GetUserStoreForSite ,
                //then a storage site that's accessible to all the Silverlight applications on the same website domain.
                using (IsolatedStorageFileStream fs = store.CreateFile("data.txt"))
                {
                    StreamWriter sw = new StreamWriter(fs);                  
                    sw.Write(txtname.Text);                  
                    sw.Close();
                }
                txtname.Text = string.Empty;

            }
            catch
            {

            }
        }


Let us concentrate on this line.

IsolatedStorageFile
store = IsolatedStorageFile.GetUserStoreForApplication();

Silverlight creates isolated stores automatically. To interact with an isolated store, you use the IsolatedStorageFile class. You get the IsolatedStorageFile object for the current user and application by calling the static IsolatedStorageFile.GetUserStoreForApplication() method, as shown here:

Step 4: Press F5 and test write and read buttons.

Step 5: Now let's concentrate on how disk storage works. Initially, each Silverlight application gets 1 MB of space in it's isolated store. You can examine the IsolatedStorageFile.AvailableFreeSpace property to find out how much free space remains. If your application needs more space, you can use an option: the IsolatedStorageFile IncreaseQuotaTo() method.

We must request a value that's higher than the current quota. Otherwise, you'll receive an exception. That means you can't use the IncreaseQuotaTo() method to ensure that there's a certain level of free space.

If everything goes well, you will be presented with something such as shown in the figure below.

 



Press Release - Premier European HostForLIFE.eu Launches Silverlight 5 Hosting

clock February 3, 2012 06:51 by author Scott

HostForLIFE.eu was established to cater to an under served 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. We proudly announces the availability of the Silverlight 5 hosting in our entire servers environment.

You can start hosting your ASP.NET MVC 3 site on our environment from as just low €3.00/month only. For more information about our new product, please visit our site at
http://www.hostforlife.eu/Silverlight-5-European-Hosting.aspx.

“Today, we are really happy to announce the release of Silverlight 5 on our hosting environment. Silverlight 5 is part of a rich offering of technologies from Microsoft helping developers deliver applications for the web, desktop, and mobile devices. I personally would like to thank the people who have assisted in completing this project.” Said CEO of HostForLIFE.eu, Anthony Johnson.

“Silverlight 5 delivers great features that allow hardware H.264 decoding, adapting it better for video content. It also sports an improved graphics stack with 3D support, using the  XNA API.  This makes Silverlight 5 a more mature and capable platform for developing rich internet application.” Said John Curtis, VP Marketing and Business Development at HostForLIFE.eu. “We believe that our Silverlight 5 provide great opportunity to web developers.”

Silverlight 5 also includes the following developer related enhancements:

- XAML Debugging with breakpoints for binding debugging
- Implicit data templates for easy UI reuse
- Double (and multi) click support
- GPU-accelerated XNA-compatible 3D and immediate-mode 2D API
- Low-latency sound effects and WAV support
- Real operating system windows and multi-display support
- Significant performance improvements, fixes and much more

For complete information about this new product, please visit our official site at
http://www.hostforlife.eu.

About us:

We are European Windows Hosting Provider which FOCUS in Windows Platform ONLY. We support Microsoft technology, such as the latest ASP.NET 4, ASP.NET MVC 3, SQL 2008/2008 R2, and much more.

Our number one goal is constant uptime. Our data center uses cutting edge technology, processes, and equipment. We have one of the best up time reputations in the industry.

Our second goal is providing excellent customer service. Our technical management structure is headed by professionals who have been in the industry since it's inception. 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.



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