Silverlight UserControl Binding to Object Properties

On your main user control create a member variable for your object. Your object will need to implement the INotifyPropertyChanged interface. In your constructor, set the data context to the member variable. Your child user control will need to provide a dependency property and implement the INotifyPropertyChanged interface. Place your child user control on to the main user control, and set its binding in XAML to the name of the property, and set its mode to two way: Text="{Binding MyDataProperty, Mode="TwoWay}".


Silverlight UserControl Type Not Defined Exception

I have had a really frustrating day and a half trying to get a Silverlight UserControl to work in another project of mine. The solution consists of an ASP.NET website with domainservices made available to a number of Silverlight applications. The Silverlight UserControl was properly namespaced, inline with all the other projects. But could I add it to my Silverlight applications. NO!

I knew it had to be something to do with namespace issues, and I tried all sorts. In the end I managed to solve the issue with the help of my senior colleague.

The solution was as follows.

Here are the original namespaces of the web host project, and the UserControl respectively:

  • Lucid.Online.Assessments.Server (the web host)
  • Lucid.Controls.Silverlight.BlockButton (the user control)

Here are the modified namespaces:

  • LucidOnline.Assessments.Server (the web host)
  • Lucid.Controls.Silverlight.BlockButton (the user control)

Just one period caused all that hassle! Why? I don’t understand why. But at least this has fixed my issue.

So if you get the Type ” undefined exception, just check your namespaces.

Silverlight with WCF Services and SQL LocalDB Development and Deployment using CassiniDev.

Problem: You are required to deploy a Silverlight application that accesses a database via WCF Services onto a standalone computer that does not have IIS, IIS Express, or SQL Server Express installed.  Your end users are people with very limited or no real technical background that find even simple day-to-day IT tasks difficult. What database and web server do you use, and how can you make the installation as easy as possible for your end users with little, or preferably no configuration?


  • Install SQL Server 2012 or higher on your development computer.
  • Connect to the LocalDb server instance in management studio using: (localdb)\v11.0.
  • Create a new query and enter the following command to create     your database:

    create database databaseName on (name=’databaseName’, filename=’fileLocation\fileName.mdf’)

  • Create your tables.
  • Create a new Visual Studio Silverlight with WCF RIA Services project.
  • Right click on the web project and select Manage NuGet Packages…
  • Select the online option and type entityframework.
  • Install EntityFramework.
  • Add a model.  The server name should be: (localdb)\v11.0.
  • Build your project.
  • Create your domain service.
  • Build your project.
  • In your Silverlight application import the System.ServiceModel.DomainServices.Client namespace, and the namespace of your web project.
  • Create a member variable for your domain context and IEnumerable of your domain object.
  • In the appropriate method that will instantiate the domain service add the relevant EntityQuery and LoadOperation lines of code.
  • Add you method that will handle the LoadOperation.Completed event, check that args is not nothing.
  • Use your entities as required.
  • Now add a Windows Form application.
  • Download and install CassiniDev.
  • In your Windows Forms application add a reference to the CassiniDev4-lib.dll.
  • For the tutorial on Using CassiniDev to host ASP.NET in your application.
  • Build your solution.
  • Copy the deployable portions of the web project into the WebContent folder located in the Windows Forms executable’s root folder.

On the client computer that you are going to deploy the solution on you will need to install:

  • Silverlight 5;
  • the .NET Framework 4.02 update (NDP40-KB2544514-x86-x64.exe);
  • and the SQL Server Local Database (SqlLocalDB.msi).

There is the Express Edition of InstallShield which is free to use.  Use this to create a Basic MSI project that will silently install the above components, and copy your application onto the client computer.  Create a desktop shortcut.  Run the executable from the shortcut to test that the application is working.

Applying Multiple Animations On A Single Property Within A Silverlight5 Application

I came across a situation where I needed to perform multiple rotations on a single object’s property within the same storyboard. However, when I tried to apply two rotations to the same image, I received an error stating that I could not apply multiple animations to the same property within the same storyboard. This had me stumped for a while. That is until I came across Peter Gerritsen’s article called ‘silverlight: multiple animations on one property through transforms‘. By using the DoubleAnimationUsingKeyFrames object in conjunction with a TranformGroup and multiple RotateTransform objects I was able apply multiple rotations to a single element on the same storyboard.

The XAML Code:

<Canvas x:Class=”SilverlightScriptedAnimationHarness.MainPage” xmlns=”;





d:DesignHeight=”768″ d:DesignWidth=”1024″>

<Image Source=”/SilverlightScriptedAnimationHarness;component/Images/image.jpg” Canvas.Top=”275″ Canvas.ZIndex=”100″ />

<Canvas x:Name=”LayoutRoot” Background=”transparent”>


<Storyboard x:Name=”MultipleRotationsStoryboard” AutoReverse=”True” RepeatBehavior=”Forever”>

<DoubleAnimationUsingKeyFrames x:Name=”RotateAnimation1″ BeginTime=”00:00:00″ Storyboard.TargetName=”RotateTransform1″ Storyboard.TargetProperty=”Angle”>

<EasingDoubleKeyFrame KeyTime=”00:00:05″ Value=”360″>


<CubicEase EasingMode=”EaseInOut” />




<DoubleAnimationUsingKeyFrames x:Name=”RotateAnimation2″ BeginTime=”00:00:00″ Storyboard.TargetName=”RotateTransform2″ Storyboard.TargetProperty=”Angle”>

<EasingDoubleKeyFrame KeyTime=”00:00:05″ Value=”360″>


<CubicEase EasingMode=”EaseInOut” />






<Rectangle x:Name=”RotateRectangle” Fill=”Blue” Width=”50″ Height=”50″ Canvas.Top=”240″ Canvas.Left=”200″>



<RotateTransform Angle=”0″ CenterX=”0″ CenterY=”0″ x:Name=”RotateTransform1″ />

<RotateTransform Angle=”0″ CenterX=”50″ CenterY=”50″ x:Name=”RotateTransform2″ />




<Button x:Name=”MultipleAnimationsOnProperty” Canvas.Left=”800″ Canvas.Top=”200″ Width=”100″ Height=”75″ Content=”Multiple” />




The VB.NET Code:

Partial PublicClassMainPage
Private Sub MultipleAnimationsOnProperty_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MultipleAnimationsOnProperty.Click
  End Sub
End Class

Silverlight 5 and XNA 3D White Page

When you build a web application using Silverlight 5 and XNA 3D, you may find that your application does not load and appears as a white block. The solution is simple.

In the area of your page where you expect to see your silverlight application, right click to bring up the Silverlight menu. Click the only menu option there is that says Silverlight. This will bring up the Microsoft Silverlight Configuration dialog.

Microsoft Silverlight Configuration

On the Permission tab click on allow to enable 3D graphics.

Custom tool error: Failed to generate code for the service reference …

Within a Windows Phone 7 Silverlight client, when updating a service reference I frequently receive the following error message: “Custom tool error: Failed to generate code for the service reference ”. Please check other error and warning messages for details.” When I get this error, the code generator fails to generate the Reference.cs file. This has the knock on effect of generating a number of errors as my service reference is no longer recognised by VS2010.

Completely removing the service references, deleting the bin, obj folders and service reference folders, and removing the service reference pointers in the project file and readding the service references has no effect at all. The custom tool still fails to generate the Reference.cs file. That means that the problem has to lie with the WCF Service.

I will now investigate the WCF Service, and see if this yields any clue as to what is going on.

It is indeed the service, there is something wrong with my deployment. My initial thinking is that there are some missing dependencies that my service relies on. And I am right. There were some missing DLLs, and data files that the service depends upon.

Another problem has arisen, in that the Exception policy for the Enterprise Framework as set in the Web.config file is being set more than once. This generates an error, and yet it is only located in one place! The simple fix is to simply comment the policy field out in the config file.

Testing the deployed service now works in the WCF Test Client, after modifying the client config to increase the timeouts, maximum buffer size, and maximum message received size.

Now that have I my deployed service working, surely I can create my service reference and have the custom tool generate the source code for the Reference.cs file right? No. Hmmm, this is rather frustrating. But never mind, there is a solution. I just have to rack my brains a little harder.

I have tried to delete the service reference and recreate it with a different filename as some suggest on WCF forums, but this hasn’t worked for me. Time for a cup of tea and some thinking time.


I have found the cause of the problem. Team Foundation Server was intefering with the regeneration of the service reference. To solve this issue, I deleted the bin folder, the obj folder, the service reference client config file, the service references, and the service reference folder. I then saved the solution and checked in the changes to Team Foundation Server, and confirmed the pending deletions. Then I recreated the services, and lo and behold the Reference.cs file was created with the generated source code.

In summary, when your client fails to create a service reference the first thing to check is that the service is working correctly using the WCF Test Client. Once you have established that the service is working, update your service reference. If the source code for the Reference.cs file has not been generated by the custom tool, delete the bin folder, obj folder, service reference folder with all its contents, and the client service config file. Save the project and check in the project confirming all deletions. Then proceed to add the service references. At this point you should have the fully generated service references with source code and the basic client service config file. The final stage is to modify the bindings in the config file to include the timeouts set to “00:10:00”, the MaxBufferSize set to 2147483647 and set the MaxReceivedMessageSize to 2147483647.

A very painful excersise, but one with a happy ending:)

Update: 2011-05-27

This issue raised its ugly head again. I followed the steps above to fix the issue but they didn’t work in my project. So I created a new project that was not in TFS and added the service reference and it worked!

I had a look at the ServiceReferences.ClientConfig and noticed that the basicHttpBinding and the client endpoint were missing for the reference I was trying to add. So I added these entries to the ServiceReferences.ClientConfig file and then added the service reference, and sure enough the References.cs file was generated correctly.

Creating Service Reference: Failed to generate code for the service reference

When accessing a remote SQL Server database from a Windows Phone 7 device, the preferred way to interact with the database is through the implementation of a WCF Service. This is the scenario that we will work with. Say we have a SQL Server database sitting on a remote server. On the remote server, we also have IIS installed and our WCF Service application up and running that provides access to the database via LINQ to SQL classes, and the client device that communicates with the database via the WCF Service is a Windows Phone 7 Device.

If we change the structure of the database and update the LINQ to SQL schema, we need to update our service references within the client project. However, when we update the service reference we get the error ‘Failed to generate service reference’.

The first thing to check is that our service works using the VS2010 WCF Test Client. If the WCF Service fails within the test client, we need to fix the relevent issues that prevent the service from successfully running. Once we have the service running successfully with the VS2010 WCF Test Client, we then delete the service references and client config files from within the Windows Phone 7 application. After we have done this, we close the project down and edit the Windows Phone 7 project file in Notepad and remove any remaining references to the service references. We also delete the project user properties file. When we are done deleting everything, we save the project file and reopen the Windows Phone 7 solution and re-add the service references. And now everything works fine.