I played poker with a Tarot deck — got a full house. Two people died. — Steven Wright
This is the first program I’ve completed using Windows Presentation Foundation (WPF). Although I started coding it in Visual Basic then converted the project when I was about 60% through to WPF. Why do this? I needed some animation and simple image control manipulation which would be a pain in VB but a piece of cake in WPF. I copied and pasted my VB classes and windows directly into my new WPF project. Then I tackled the syntax differences like Label.Text => Label.Content and recreated the VB windows as WPF pages using the same control names whenever possible in Expression Blend ( e.g., VB PictureBox ppb1 became WPF Image ppb1).
I made the card animations as Storyboards in Expression Blend and set up to trigger them from the VB code. This snippet shows how the animation is triggered from code with BeginStoryboard().
'use this to deal dog cards Dim d As Animation.Storyboard d = CType(Me.FindResource("DealDog"), Animation.Storyboard) 'assign the Blend animation For i As Integer = 1 To 6 'turn on card visibility ImageVis("dpb", i, True) Next Me.BeginStoryboard(d) 'play animation
I was impressed by how easy it was to create and modify these animations in Expression Blend. As a long-time VB coder it took me awhile to understand how WPF uses project resources (for instance, loading an Image.Source from a relative project resource folder – in this case imagen is a StringBuilder object containing “/Images/Cards/back0.gif”),
Dim bm As New BitmapImage bm.BeginInit() bm.UriSource = New Uri(imagen.ToString, UriKind.Relative) bm.DecodePixelWidth = 83 bm.EndInit() pb.Source = bm 'assign the card image to the WPF Image pb
and there were more than a few things that cannot be done in WPF (like setting a random screen destination for an animation). Overall, I’m happy with the result. If you are interested, the Visual Studio source code is available on CodePlex.
Basic 3 Tarot – the game is available as freeware. Here’s a link to the Windows install package: