Posts tagged ‘XAML’

November 11th, 2010

My guest chapter for Hacking Silverlight: Community Edition

Hacking Silverlight: Community Edition CoverI’ve been working hard to stay involved in the local user group community. My adventures put me in touch with a local Silverlight MVP, David J. Kelley. David has been working on a number of projects, one of which is a follow-up book to his first title Hacking Silverlight. This new edition is titled Hacking Silverlight: Community Edition. David asked me to write a chapter that highlights some of the great projects that are on My chapter is titled Codeplex Projects Everyone Should Know About and you can read it here.

In addition to the book there is a great Code Browser that you can install which will guide you through learning the XAML/C# techniques highlighted in the book. It was a great learning experience and I hope to be able to contribute more in the future.

October 9th, 2008

Access WPF Storyboard in XAML from code-behind (C#)

At more than one time working with WPF I’ve wanted to create a generic Storyboard using Blend because it saves me time and gives me a nice time line type layout to create/tweak my Storyboard. What happens is when you save the Storyboard it’s added to the Windows.Resources collection the XAML. In Silverlight you can access these Storyboard resources directly using their x:Name value. In WPF, however, you need to do it slightly differently.

  • First, You need to specify x:Key for each Storyboard
  • Storyboards must be found using TryFindResource:

    Storyboard myStoryboard = (Storyboard)TryFindResource(“myStoryboard”);

  • TryFindResource will only work if the Storyboard is in the Window.Resources section of the XAML and you’re in the code-behind of that XAML
  • Once you have the reference to the Storyboard contained in a variable you can call the various Storyboard methods on it. To run it, use the Begin method:


Here is a quick code snippet to help you out.

Here is the XAML: