The team blog of the Expression Blend and Design
In Blend you use the Pen tool to draw lines and they appear in the XAML as <Path> elements. But after you’ve drawn your lines and you test your application, the Paths appear immediately: they don’t replay the gestures you used to create them. But sometimes that’s the effect you want, so how do you do that? The manual way is only practical if you have very few points. First draw out a Path consisting of straight segments. Then create a new Storyboard, move the playhead forward a tenth of a second and, using the Direct Selection tool, move the last point to the same position as the second-to-last point. Move the playhead again and repeat, each time moving an increasing number of points back to the previous position. When all your points are at the same position as the very first point, move the playhead to time 0 and click the Record Keyframe button. Now reverse the Storyboard and you’re done.
Any more than a very small number of points and you’ll need an automatic way of generating the Storyboard. You can do that with the code in the assembly dll built from the PathScribbler project I’ve provided below:
PathScribbler works with WPF paths but you could easily port the code to work with Silverlight. After building the dll and referencing it in your project, the way you use it is you first draw your Path (which may contain curved segments but they will be straightened by the PathScribbler code) and then you create a new, empty Storyboard. Finally just call PathScribbler.Generate() and pass the name of the Storyboard into which the animations are to be generated along with some other optional parameters. Then you can trigger your Storyboard any way you wish.
The PathScribbler project is contained in an example project named PencilWriter attached to the post. For this project I made a TextBlock into a Path and I trigger my Storyboard when the main window is clicked. Build and run the project then click the window and wait a moment until the animation is generated and then begins. Hope you have fun with PathScribbler!
PingBack from http://hoursfunnywallpaper.cn/?p=1652
In Blend you use the Pen tool to draw lines and they appear in the XAML as <Path> elements. But
Bill Reiss announced a SL Game contest, Matt Berseth with Custom DataGrid icons, Palard Julien provides
I love this app! I was just searching for a sample Silverlight application that could animate the pencil/handwriting action... This one works great! Hopefully I can make customizations and test my own creativity:) Thanks!
i'm very new to silverlight and so i'm not sure how to use pathscribbler correctly. any examples with silverlight?
Hi rodchar. Feel free to re-use the source code - just paste the PathScribbler class source code right into your Silverlight project and make sure it builds (I might be using one or two WPF-isms in there that will need to be ported). If you build the PathScribbler project as posted you'll get a WPF dll. And referencing that from a Silverlight project won't work and that looks like the error you're getting.
Great post, really enjoyed the read!
I would really like to look at this but the link seems to be dead. Can you please look into it or if possible forward me the source zip?
I have tried to get this to work with GeometryGroup for a few days now with no success.
This will iterate through the Geometrys successfully but the implementation of this logic into your solution is not idiot prof, so i am out of luck.
Geometry geom = path.Data;
if (geom is GeometryGroup)
GeometryGroup g = geom as GeometryGroup;
foreach (object fig in g.Children.AsEnumerable())
if (fig is StreamGeometry || fig is PathGeometry)
can't find the folder, please upload it again or send it to me, thank you.