I built one of those "sliding" puzzle games with Silverlight (I remember that there used to be a similar but much more elaborate one with WPF for a while).
Image is below;
and links to the running sample. The main thing that I wanted to play with here was the idea of painting with a generic brush (be it Image or Video) and how powerful that is and it just worked a treat in building this.
Playing with the Alpha, I did struggle with a few things - not sure whether this is a "lack of knowledge/docs" thing or whether it's just stuff that's a bit rough-and-ready with the Alpha.
- I found it pretty tricky to re-use anything. For example, if I created a Brush to paint a rectangle then I'd expect to re-use that Brush to paint another rectangle but I found that throws exceptions whereas if I re-create the Brush every time then that is fine.
- I found it pretty tricky to create a Storyboard from code. I had quite a few goes at this and, no matter what I tried, I struggled to build a Storyboard using the object model. In the end, what I had to do was to stick a hard-coded string into my code with the XAML that I wanted in it and then call XamlReader.Load on that string to give me an object graph that's rooted by a Storyboard and then I could manipulate that Storyboard from the object model. That is, I ended up doing something like this;
string xaml =
string.Format(
"<Storyboard " +
"xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' " +
"xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' " +
"x:Name='{0}' " +
"Storyboard.TargetName='{1}' Duration='0:0:1'>" +
"<DoubleAnimation x:Name='{2}' By='0' Storyboard.TargetProperty='(Canvas.Left)'/>" +
"<DoubleAnimation x:Name='{3}' By='0' Storyboard.TargetProperty='(Canvas.Top)'/>" +
"</Storyboard>",
StoryboardName,
RectangleName,
LeftAnimationName,
TopAnimationName);
Storyboard sb = (Storyboard)XamlReader.Load(xaml);
Rather than just doing Storyboard sb = new Storyboard(); sb.Children = .......;
I'm sure there's some way around this that probably involves setting the right DependencyProperty but I did try quite a few and couldn't quite get there.
The only other thing that I struggled with was that I originally had an animation with a duration of "0:0:0.5" and what seemed to happen with that animation was that it only ran to half of its expected value. Not sure if this is something odd about timers etc. but I found that setting a value below 1s seemed to result in a peculiar animation.
The source project is here if you want to play with it.
Posted
Tue, May 8 2007 10:48 AM
by
mtaulty