views:

181

answers:

1

I'm wondering if anybody knows any good (free) behaviors for Blend/Silverlight 4

Specifically I'm looking for a behavior that I can drop on a TextBlock to make it scroll horizontally or a behavior that will "flash" text in a TextBlock (blinking text). But I'd love to hear about any behaviors you've been using or know about.

As an example, I've got a very basic "flashing text" behavior

public class FlashTextBehavior : Behavior<TextBlock>
{
    Timer flashTimer;

    public FlashTextBehavior()
    {

    }

    protected override void OnAttached()
    {
        base.OnAttached();
        flashTimer = new Timer(new TimerCallback((o) => 
        {
            Dispatcher.BeginInvoke(() =>
            {
                if (AssociatedObject.Visibility == Visibility.Visible)
                    AssociatedObject.Visibility = Visibility.Collapsed;
                else
                    AssociatedObject.Visibility = Visibility.Visible;
            });               
        }), null, 0, 750);
    }

    protected override void OnDetaching()
    {
        if (flashTimer != null)
            flashTimer.Dispose();

        base.OnDetaching();
    }
}

Of course it can be improved upon, but I'm really interested in what other people have come up with.

+3  A: 

Check out my blog with a way to scroll text like a marquee: http://michaelcrump.net/archive/2010/07/08/enabling-scrolling-text-in-wpf-xaml-code-snippet.aspx

mbcrump
Very helpful post! Thank you!
Aggelos Mpimpoudis
I would use the animation trigger for the blinking also like mbcrumps example
Jason Stevenson