Subscribe to our RSS Feeds

Welcome to Silverlight Blog!

Hello Visitors !

You found a Blog about Microsoft Silverlight by Sascha Baumann,
Freelance Software Developer based Berlin, Germany.

If you need development, coaching or a
second opinion - Just contact me.

Have fun looking around :o)

Sascha Baumann

Easy usage of INotifyPropertyChanged with Property-Attribute

No Comments »

Hello everyone,

today I want to share an implementation I’m using in my personal prototyping-Framework for Silverlight. This is important to mention, because I have tested it only for “works” but not including any productive parameters like memory-usage or processing-time.

The meaning of a prototyping-framework for me is to get thinks working as quick as possible, to show the outcome to my customer. There are some things I need very often, and so I’m using base-classes a lot.

Click here to read more.. »

Silverlight 4, Various Juni 9th 2010

Silverlight Localization

No Comments »

Hello everyone,

I originally planed to write a blog-post about the right way to localize Silverlight Apps. While researching I came across two really good posts about that topic already. So instead of writing the same stuff again, I follow an extended D.R.Y.-Principal ( I might call it D.R.O.P – Don’t repeat other people ;) ) and point you in the right direction instead :o

A short but clear post about Localization was written by Patric Schouler on dotnet-redzone.blogspot.com.

If you like more detail and "Hands-On"-Experience have a look at the Post "Localizing Business Application" by Brad Adams.

Keep on improving !

Sascha

Various Mai 24th 2010

Generic View Models in Silverlight

No Comments »

I like using Base-Classes for any kind of “Class-Group”. Very prominent groups are Models and ViewModels in Silverlight-Applications.

The ViewModel-Baseclass can hold any functionality, that applies to every ViewModel inheriting from it and, if we are talking about Generics, can be very convenient to use.

For example, if I want to apply the factory-pattern to my ViewModels and want every Model to have a static Create-Method I can simply implement this Method in the Base-Class.

public class ViewModelBase 
{ 
	public virtual ViewModelBase Create() 
	{ 
		return new ViewModelBase(); 
	} 
}

Of cause, without Generics we are limited to the return-Type. We could now override this method in every specific ViewModel to at least return the right ancestor of ViewModelBase. An easier way is, to use Generics for this case. The class could look like this :

public class ViewModelBase<TViewModel> where TViewModel : ViewModelBase 
{ 
	public virtual TViewModel Create() 
	{ 
		return Activator.CreateInstance(typeof(TViewModel)); 
	} 
}

Now we can simply create our new specific ViewModel like this

public class MyViewModel : ViewModelBase<MyViewModel>

to get what we want generically.

 

Another possible scenario would be the following. We know, every ViewModel contains a Collection of Models, all inheriting from a class called ModelBase. we could extend out code the following way:

public class ViewModelBase<TViewModel> where TViewModel : ViewModelBase 
{ 
	public virtual TViewModel Create() 
	{ 
		return Activator.CreateInstance(typeof(TViewModel)); 
	} 
 
	public List<ModelBase> MyList {get;set;} 
}

or, the better way, we could extend our Generic header to be type safe.

public class ViewModelBase<TViewModel, TChildModel> 	
                                        where TViewModel : ViewModelBase 
					where TChildModel : ModelBase 
{ 
	public virtual TViewModel Create() 
	{ 
		return Activator.CreateInstance(typeof(TViewModel)); 
	} 
 
	public List<TChildModel> MyList {get;set;} 
}

Defining a Class by

public class MyViewModel : ViewModelBase<MyViewModel, MyModel>

Like always, if we talk about inheritance, you should avoid to go too far with that. I implemented a Framework I use for rapid prototyping where a lot of things are done in the base-class via reflection, but in a productive environment its not always what you want. Plan your development as precise as possible.

  • What do you want to be individually implemented by each ViewModel ?
  • When is it a good thing to implement it in the Base-Class ?
  • How confusing is you inheritance for other developers ?

 

Good Luck :o

Silverlight 4, Various Mai 14th 2010

Finally: Silverlight 3 and Silverlight 4 Beta Runtime on same computer

No Comments »

I read very often things like “Should work, cause its downward compatible”. But I’m too long in the business to trust sentences like this – so basically If I write a Silverlight 3 App for a customer I want to test it with the SL 3 Runtime, if I play around with the new SL 4 Features, I obviously need SL 4 Runtime. Are you like me ? Don’t you like VMs for these small requirements ?

Click here to read more.. »

Silverlight 4, Various Februar 16th 2010

Improve Silverlight Hittesting (Pixelbased)

No Comments »

Many of you will know, that Silverlight 3 has a new class called WritableBitmap. We can now create Bitmaps on-the-fly.  At the moment one interest of mine is Silverlight Game-programming and I thought, this class may also help to build pixel based Collision-Detection.

Guess what, I found an article from Andy Beaulieu doing exactly that:

" Improved HitTest Method for Silverlight 3" from Andy Beaulieu

Various Januar 5th 2010

Silverlight Development with Eclipse – Eclise4SL

No Comments »

There is a new Kid in SL-IDE-Town, and its called Eclipse4SL. To be honest, it isn’t really new, cause development started in 2008. But end of  2009 they released Version 1.0.

The Features of this Version are:

  • Silverlight 2.0 support
  • C# code editor with syntax colorization, keywords and template code completion assist
  • Automatic Build & Run
  • Configurable Web application launch facilities
  • Silverlight Project System and Silverlight Compiler: both an advanced project system for creating Silverlight applications and media experiences.
  • XAML Editor & Preview: advanced, standards-compliant XAML editor with code hinting and code completion features which helps detect and correct coding errors.
  • Move and Rename refactoring
  • Advanced Media Features
  • Cross Platform Capabilities (Mac version)
  • Complete user documentation & Prescriptive Tutorials
  • Defects & Regression Testing
  • Developer Usability Testing

 

Version 2.0 is planned for Spring 2010. This is the roadmap:

  • Silverlight 3.0 support
  • Completion of re-organization Silverlight development environment
  • Completion of the Extensibility, Support for Multiple Projects
  • Improvements to Mac Platform
  • Completion of Silverlight 3.0 Runtime Support "out of browser"

 

More Information can be found on the projects website www.eclipse4sl.org

If you are a Mac-User, there is also a plug-in for you. Check out the Microsoft Interop Website for Eclipse4SL.

Various Januar 2nd 2010

Happy new Year

No Comments »

Hello everyone,

I wish all of you a relaxing and successful 2010. See you on the other side :o )

Sascha

Various Dezember 31st 2009

Silverlight in Webslices

2 Comments »

I had a little inspiration during the holidays – tried it out – and it worked.

With Internet Explorer 8 Microsoft introduced a new feature called Webslices. Little pieces of information within your browser-bar (most commonly) about site-updates.

Now I tried to put a Silverlight app into a Webslice.

Herefor I created a new Silverlight App with a testpage like this (created automatically)

<form id="form1" style="height: 100%;">
<div id="silverlightControlHost">
<object width="100%" height="100%" type="application/x-shockwave-flash">
<param name="source" value="ClientBin/SilverlightWebslice.xap" />
<param name="onError" value="onSilverlightError" /><param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40624.0" />
<param name="autoUpgrade" value="true" />
</object></div></form>

In my Silverlight-App I placed a Textblock saying “Welcome to my Silverlight Webslice”.

<Grid x:Name="LayoutRoot">
        <TextBlock Text="Welcome to my Silverlight Webslice"></TextBlock>
  </Grid>

And then, in default.aspx I put the Webslices-Code

<form id="form1">
<div id="SliceID" class="hslice" style="display: none">
<span class="entry-title">Silverlight Slice
<a style="display: none" rel="entry-content" href="SilverlightWebsliceTestPage.html">Alternative</a>
</div></form>

and voila, a silverlight Webslice.

silverlightwebslice

Have fun playing arund with it :o )

Before I forget, there is an alternative for Firefox Browser called WebChunks. Unfortunately it doesn’t work for the current Version at the moment, hope the developer will keep on working on it.

Sascha

Various Dezember 31st 2009

Silverlight 4 beta released – Some useful information

No Comments »

Hello everyone,

as most of your Silverlight-Interested-People might already know, Microsoft has released the beta-version of the upcoming Silverlight Version 4. Lot of things are new, but instead of spreading it out myself, I want to post some references to really good summaries and tutorials I found.

All I really needed to do, to get started with SL 4 was (beside installing Visual Studio 2010 Beta 2 which I already had on my machine) go to this page:

GetStarted Page for Silverlight 4 beta

download an install the tools. the new runtime is in the package too.

A pretty good summary of the new features can be found on Tim Heuers Blog:

Silverlight 4 Beta – A guide to the new features

And there is also a series of articles published by Alex Golesh that are hands-on-tutorials for some of the new features

 

I will surely write more about this topic during the next weeks, so stay tuned :o )

Sascha

Silverlight 4, Various November 22nd 2009

Styles from different files as static resources

No Comments »

Hello everyone,

to start a silverlight project, i have a kind of default-template which I enriched with a CSS-like decentralized style today. This is done very easy now in Silverlight 3. First you habe to set up a file containing your style. In my case it was a file in a new Styles folder called TextBock.Default.xaml where I entered this dummy code:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:Windows="clr-namespace:System.Windows;assembly=System.Windows">
    <Windows:Style x:Key="TextBlock.Default" TargetType="TextBlock">
        <Windows:Setter Property="FontFamily" Value="Times New Roman"/>
        <Windows:Setter Property="FontSize" Value="16"/>
        <Windows:Setter Property="Foreground" Value="Black"/>
        <Windows:Setter Property="LineHeight" Value="26"/>
    </Windows:Style>
</ResourceDictionary>

after that, I created a MergedDictionary in my app.xaml like that:

 <Application.Resources>
         <ResourceDictionary>
             <ResourceDictionary.MergedDictionaries>
                 <ResourceDictionary Source="Styles/TextBlock.Default.xaml"/>
             </ResourceDictionary.MergedDictionaries>
          </ResourceDictionary>
     </Application.Resources>

from now on, you can call this style like you’re used to with {StaticResource TextBlock.Default} within your application. Nice way to manage the styles as I think, and much easier to maintain than having all your styles plugged in your app.xaml in total.

Have fun playing with it :o )
Sascha

Various Oktober 27th 2009