SilverlightExamples.NET

Latest Silverlight Samples, Examples, Demos and Tutorials.

Load Bitmap Image From Resource in a Single Line of Code

clock April 8, 2008 15:42 by author Neo

If you read my recent article "How to Get Files From Resources in Silverlight 2.0", you'll see that loading a file embedded as resource takes only a few lines of code. You also have to remember the formats of the URI. Well, that is going to change today, because now you'll need to write just a single line of developer-friendly code.More...

Currently rated 3.5 by 2 people

  • Currently 3.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


How to Get Files From Resources in Silverlight 2.0

clock April 7, 2008 03:14 by author Neo

Questions like "How to load an embedded bitmap programmatically?" appear in Silverlight.net forum every single day, and some people actually think it is impossible to do such thing in Silverlight 2.0. Well, the truth is that not only is it possible but it is also damn easy.More...

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Open File Dialog in Silverlight

clock January 18, 2008 02:40 by author Neo

Silverlight 2.0 Alpha introduced OpenFileDialog control which allows Silverlight applications to open and read *local* files outside Isolated Storage. It's better than the HTML <input> tag which is widely used for uploading files in web page. Well, like HTML <input>, OpenFileDialog could be used to build a file uploader quickly. Both must prompt user to select files. But unlike HTML <input>, OpenFileDialog control could be used to read and process the file data locally in Silverlight application. This is pretty powerful since Silverlight application will not need to upload the files to server for processing. What's more is that OpenFileDialog allows user to select multiple files at once. No need to create multiple instances of OpenFileDialog for that. Let's see some examples:More...

Currently rated 3.7 by 3 people

  • Currently 3.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Fluid Canvas in Silverlight

clock January 17, 2008 06:37 by author Neo

So you wanted the root canvas to scale proportionately to the host element to achieve fluid layout, and you tried setting Width=”100%” or Height=”50%”, but then horror struck because of this parser error: “Invalid attribute value 100% for property Width/Height”.  Ok, to tell you the truth you cannot set “%” to the Width and Height properties because the % is not accepted. Read on for the solution.

The BrowserHost instance has the Resize() event which fires every time the host element is resized and the ActualWidth/ActualHeight properties which tells the dimension of the host element. So, to automatically resize the root canvas, handles the BrowserHost.Resize() event, and from there you can resize the canvas. Let’s sum it up with VB.NET and C# code:More...

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Creating Cool Draggable Window in Silverlight

clock January 13, 2008 22:23 by author Neo

 
 

Silverlight is often dubbed as the would-be better platform for creating Rich Internet Applications. But to date, I’ve seen only applications sitting duck in the browser. Well, I’m not saying that those are not great RIA, but for goodness sake, I want to see something different like a Silverlight application flying around in the browser among HTML elements, or at least a window in Silverlight that could be dragged around. This motivates me to create a proof of concept.

This tutorial basically demonstrates how to create and overlay a draggable window on HTML body in Silverlight 1.1, using managed code and DOM. For simplicity, this sample uses an alpha-blended background PNG image to cast the shadows and make the ‘see-through glass’ effect on the LCD screen.More...

Currently rated 4.6 by 5 people

  • Currently 4.6/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Silverlight Can Go Full Screen and Back

clock January 12, 2008 01:29 by author Neo

So you want your Silverlight video player to play in full screen? No problem! It's pretty easy to go into full screen mode, hiding everything including browser frame, in Silverlight. It's just a line of code:

Application.Host.Content.IsFullScreen = True 

While in full screen mode, user can press ESC key to exit full-screen mode, or your Silverlight application can exit programatically by:

Application.Host.Content.IsFullScreen = False

You can easily toggle between full screen modes by:

VB.NET
Application.Host.Content.IsFullScreen = Not Application.Host.Content.IsFullScreen

C#
Application.Host.Content.IsFullScreen != Application.Host.Content.IsFullScreen;

The Content class exposes two events FullScreenChanged() which fires when the full screen mode is changed, and Resized() event which fires when the host element is resized (not when browser is resized). You can use these events to detect when user gets into and out of full screen mode. It's also worth mentioning that all keyboard events will not fire in full screen mode, only mouse events will. This feature is to protect user from password spoofing and other impersonation attacks.

View Online Demo - Download Source Code (14.34 kb)

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Store and Read Files in Client's Computer Using Isolated Storage

clock January 10, 2008 01:49 by author Neo

Says your application downloads some data files and need to save them locally in the client's computer for subsequent uses. Well, Silverlight in partial-trust mode cannot access client's file system directly, because that would seriously compromise the client's computer. So, Silverlight team devised an ingenious solution by creating a sandboxed virtual file system as known as Isolated Storage. As the name implies, each Silverlight application is given an isolated storage for its own use, up to about 1MB in Silverlight 1.1 Alpha. This opens up a lot of good possibilities like saving user settings, temporary files, form inputs, etc. Without further ado, let's see how to save a text file:More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


How to Get Information About Browser, Web Page and Cookies

clock January 10, 2008 00:45 by author Neo

 

As Silverlight application is hosted in web browser, you might somehow want to get some information about it like browser name, version, platform or user agent. Or you might want to check whether cookies are enabled before reading/writing them. It's pretty easy indeed, because Silverlight exposes the references to the browser and page instances in System.Windows.Browser namespace. They're all there. HtmlPage holds the information of the current web page, and BrowserInformation holds that of the browser. Here's a quick example of how to get the name of the browser:More...

Currently rated 3.7 by 3 people

  • Currently 3.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Execute Code String at Runtime with Silverlight 2.0 DLR

clock January 4, 2008 03:40 by author Neo

Requisites

  • Microsoft Visual Studio 2008
  • Silverlight 1.1 Alpha November Refresh or Newer

Introduction

One of the best additions in Silverlight 2.0 is the implementation of the Common Language Runtime and then the Dynamic Language Runtime, both of which were missing in Silverlight 1.0. Let’s dig a bit deeper in this CLR and DLR thing.

Silverlight 2.0 CLR is a stripped down version of .NET Framework 3.5 featuring the same type system, JIT compiler, garbage collector and a shipload of the same .NET 3.5 namespaces. Silverlight CLR allows .NET code to execute in a sandboxed environment on the client-side. But here’s the problem: Full .NET Framework has the full implementation of System.CodeDom framework which allows .NET code compilation at runtime, but Silverlight CLR strips out 99% of System.CodeDom namespace for security and space concerns. Therefore, you can no longer compile .NET code through the CodeDom in Silverlight. This is when DLR comes to rescue!More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


UserControls as Screens Pattern

clock December 30, 2007 20:48 by author Neo

Pete Brown is showing how to handle multiple screens (like Wizard control) and modal dialog in Silverlight. The pattern illustrated provides a way to simulate windows in what is inherently a non-windowed system: the Silverlight plug-in running inside the browser.

Online Demo - Source Code - Direct Download

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Get Started With Silverlight 1.1

clock December 21, 2007 19:58 by author Neo

I've found this nice tutorial video by Scott Guthrie. He demonstrates how to build a simple Silverlight application using .NET in about 23 minutes.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Search

Calendar

<<  July 2008  >>
SuMoTuWeThFrSa
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

Archive

Tags

Categories


Blogroll

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2008

    Sign in