Archive | Silverlight RSS feed for this section

Doesn’t Denmark like HTML5?

14 Jun

HTML5 is getting more and more focus. The pieces in the standard is slowing falling into place and lately Microsoft announced that the Windows 8 touch UI will support HTML5 based tiles. The HTML5 plugin (aka modern browsers) is pushing the penetration of HTML5 (75,64%) and recently it passed the Silverlight penetration (75,1%) worldwide.

But what is going on in Denmark?! The Silverlight penetration is 74,17% but the HTML5 penetration is 41,1%. Seriously!! Why is the HTML5 penetration that low in Denmark compared to the worldwide penetration. Did we forget to upgrade our browsers??

All figures are taken from riastats.com.

by xamlgeek
@xamlgeek

Slides from my Silverlight 5 talk

25 May

Tonight I’m doing a talk at “Silverlight developers in Denmark” (SLDEV). The talk will focus on the new features in Silverlight 5 and I promise I will bring lots of demos.

You can download the slides here.

by xamlgeek 
@xamlgeek

Silverlight 5 – Default file name in SaveFileDialog

25 May

A long requested feature coming with Silverlight 5 is the opportunity to set the default file name in the SaveFileDialog. In previous versions of Silverlight this missing feature have resulted in some bad user experiences, but finally it is here and it is easy to use.

To demonstrate it I have create a demo writing a text file to the computer allowing the user to set the default file name from the very beginning.

2011-05-25_013727

When the user clicks the Save-button the SaveFileDialog is shown and the user can save the file locally on the computer. The text from the TextBox is parsed to the SaveFileDialog as the default file name.

2011-05-25_013804

In the code I have set the Filter, the DefaultExt and the DefaultFileName on my SaveFileDialog instance. This provide an optimal experience for my user when saving files.

2011-05-25_013908

You can download the demo here.

by xamlgeek 
@xamlgeek

Silverlight 5 – Debugging bindings in XAML

24 May

One of the cool new tool features in Silverlight 5 is the XAML debugging features. It is limited to debugging bindings in XAML but that is an extremely useful feature.

I have created a demo showing the few steps needed to debug bindings in XAML. The demo consist of a TextBox containing a number a Button to refresh the number. The number is a random number.

2011-05-25_000737

2011-05-25_001716

The Text property of the TextBox binds to a property called “Number”. It is a Dependency Property defined in my code-behind. To make the binding work I have set the DataContext of the page to its self.

2011-05-25_002003

Whenever the Number property is updated it will automatically update the Text value on the TextBox.

As simple as it is I can spend hours looking for errors if I e.g. misspell the property that we use to bind to. Before Silverlight 5 I would get a hint in the Output window if I had a BindingExpression exception. In Silverlight 5 I can add a breakpoint to the binding directly in the XAML.

2011-05-25_003039

Debugging the XAML above I get an exception with a BindingExpression path error and enables me to easily identify the error.

2011-05-25_003230

You can download the sample here.

by xamlgeek
@xamlgeek

Silverlight 5 – Custom Markup Extensions

20 Apr

A Markup Extension is a class that decides at runtime how to set a property’s value. Markup extensions allow code to be run at XAML parse time for both properties and event handlers.

In Silverlight 4 we got some different Markup Extensions:

  • Binding
    Text=”{Binding Path=FirstName, Mode=TwoWay}”
  • StaticResource
    Foreground=”{StaticResource BlueSolidColor}”
  • TemplateBinding
    VerticalAlignment=”{TemplateBinding VerticalContentAlignment}”
  • NullExtension
    Background={x:Null}
  • RelativeSource
    DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"

With Silverlight 5 we get Custom Markup Extensions allowing us to write more specific and complex Markup Extensions.

Jeff Prosise’s have written a good sample here and Jeremy Likness have written about getting creating a custom markup extension that uses MEF to satisfy imports on object instances declared in XAML here.

by xamlgeek
@thomasmartinsen

Silverlight 5 – Elevated Trust In-Browser

20 Apr

In Silverlight 5 it is possible to enable applications to run with elevated permissions in-browser.

The code snippet below will open Notepad.exe using the AutomationFactory in Silverlight. Using the AutomationFactory requires elevated permissions.

clip_image001

To run the snippet in Silverlight 4 the application must run with elevated permissions and in out-of-browser. In Silverlight 5 it is possible to run the snippet in-browser and with elevated permissions.

There are some requirements that need to be fulfilled to be able to run with elevated permissions in-browser. The XAP file needs to be signed with a certificate present in the Trusted Publishers Certificate store. Furthermore it is necessary to add a registry setting:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Silverlight\

Add the following DWORD key "AllowElevatedTrustAppsInBrowser" with 0x00000001.

In order to make development a bit easier running using localhost (or 127.0.0.1) won’t require signing the XAP file or adding the registry setting.

You can download the demo here.

by xamlgeek
@thomasmartinsen

Silverlight 5 – ClickCount

13 Apr

Silverlight 5 enables support for multi-click input on left and right mouse button making it easier to implement features like double click. ClickCount is available on MouseButtonEventArgs.

clip_image001

by xamlgeek
@thomasmartinsen

Silverlight 5 – Multiple Windows Support

13 Apr

Silverlight 5 supports the ability to open multiple top level windows. It is required that the application run with elevated permissions.

clip_image001

Closing the main application window will cause all windows to close.

I have added a small demo here.

by xamlgeek
@thomasmartinsen

Silverlight 5 – Implicit DataTemplates

13 Apr

With Silverlight 4 came implicit styles. With Silverlight 5 comes implicit DataTemplates. Implicit DataTemplates allow DataTemplates for ContentPresenters to be selected based upon the type of its content.

In this sample I have created a Person entity containing a firstname and lastname property. For sample purpose only I have created a DependencyProperty of type Person that I can bind to in the XAML.

clip_image001

In the XAML I have added a ContentControl and bound the Content property to the Person DependencyProperty.

clip_image002

Using the new implicit DataTemplate feature I have created a DataTemplate based upon a type as a resource and the DataTemplate will be applied to the ContentControl.

clip_image003

Implicit DataTemplates can be added at Application level or locally in controls as done in the sample above.

You can download the sample here.

by xamlgeek
@thomasmartinsen

Silverlight 5 beta

13 Apr

Silverlight 5 Build 5.0.60401

Today at MIX11 keynote Scott Gu announced the beta version of Silverlight 5.

The release contains some really interesting features. Some of them got focus on line-of-business applications, some on media applications and some are more general like performance optimization and debugging bindings (yeah!).

Among the released features are:

The Silverlight 5 Beta is a major step toward the final release and includes many of the significant features already announced. The Beta download link and full list of features is available at http://www.silverlight.net. Visual Studio and Expression Blend tooling support for the Silverlight 5 Beta is also available.

Tim Heuer about the new release.

by xamlgeek
@thomasmartinsen