Xna 4.0 Game Development by Example: Beginner’s Guide


XNA 4.0 Game Development By Example authored by Kurt Jaegers is an excellent book for anyone who wants to learn XNA 4.0 games development. As you work through the book you develop some games including Flood Control, Astroid Belt Assault, Robot Rampage, and Gemstone Hunter.

This book comes in two versions one for Visual Basic .NET programmers, and the other for C# programmers. The good thing about this book is that it is very easy to read, and the examples are easy to follow. For anyone new to games programming this is a good place to start

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?

Solution.

  • 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=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;

xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;

xmlns:d=”http://schemas.microsoft.com/expression/blend/2008&#8243;

xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006&#8243;

mc:Ignorable=”d”

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”>

<Canvas.Resources>

<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″>

<EasingDoubleKeyFrame.EasingFunction>

<CubicEase EasingMode=”EaseInOut” />

</EasingDoubleKeyFrame.EasingFunction>

</EasingDoubleKeyFrame>

</DoubleAnimationUsingKeyFrames>

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

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

<EasingDoubleKeyFrame.EasingFunction>

<CubicEase EasingMode=”EaseInOut” />

</EasingDoubleKeyFrame.EasingFunction>

</EasingDoubleKeyFrame>

</DoubleAnimationUsingKeyFrames>               

</Storyboard>

</Canvas.Resources>

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

<Rectangle.RenderTransform>

<TransformGroup>

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

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

</TransformGroup>

</Rectangle.RenderTransform>

</Rectangle>

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

</Canvas>

</

Canvas>

The VB.NET Code:

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

Update WPF UI During Method Execution


Samuel Jack of Seaturtle Software Limited has produced an interesting method that allows you to force the WPF UI to update during a method call. Here is the code:

void AllowUIToUpdate() {
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, new DispatcherOperationCallback(delegate(object parameter)
{
frame.Continue = false;
return null;
}), null);
Dispatcher.PushFrame(frame);
}

This code help me to fix an issue that I had with my WPF program. The original article is called Forcing Update of UI before my function exits.

Windows Forms Element Host Fails To Display WPF User Control


Today I had the situation whereby my Windows Form would not display a WPF User Control within its Element Host Control. The source of the problem was that my WinForms project was set to target the .NET Framework 4 Client Profile. The solution was to change the setting under the compile options for the project to .NET Framework 4. Everything now works fine, although you may need to delete forms and user controls and recreate them against the new target framework.