Silverlight: toggle button bar

I have seen this asked several times: how to make a toggle button bar in Silverlight?
Some might call it toggle button group.

I have simply taken the ToggleButton template and dressed it on a RadioButton, with few minor changes like padding and corner radius.

Here is how it looks
Here is the source

Silverlight: DataGrid with integrated field (column) chooser

Not much to say here, it speaks for itself.

Right click on a column header to open the field (columns) chooser and show/hide columns.

The VisibleColumns property is always up-to-date and can be binded TwoWay, in my case I am saving it to the user preferences for consistency.

Take a look at the code to see how it’s done.

Notice: ContextMenu causes memory leak! http://silverlight.codeplex.com/workitem/7089. as long as you don’t need to remove the DataGrid you are OK.

Demo is Here
Source is here

the WPF version is over here

Silverlight: GridSplitter with a collapse button – BEST

I don’t remember where I took this control from.
It is not my work so I cannot take credit for it.
I have only fixed some stuff and made some changes to the animation.
This is by far the BEST version of this control! Use this one!
All credits goes to the anonymous developer who made it.
it should go into the Toolkit.

Demo is here
source is here

Silverlight: double click Trigger & call method Action

There are many different ways to implement double click in Silverlight, I chose to write it as a Trigger so it can be used anywhere and easily.

Of course you can write your own Action to use with that Trigger, but I wanted a most generic Action that will call a method and also could be used anywhere and easily.

The following Trigger (DoubleClick) & Action (InvokeMethodAction) classes act like any other event & handler. They can be used on any UIElement.

DoubleClick:

public class DoubleClick : TriggerBase<UIElement>
{
    private readonly DispatcherTimer _timer;
    private Point _clickPosition;

    public DoubleClick()
    {
        _timer = new DispatcherTimer
        {
            Interval = new TimeSpan(0, 0, 0, 0, 300)
        };

        _timer.Tick += OnTimerTick;
    }

    protected override void OnAttached()
    {
        base.OnAttached();

        AssociatedObject.MouseLeftButtonUp += new MouseButtonEventHandler(AssociatedObject_MouseLeftButtonUp);
    }

    void AssociatedObject_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        UIElement element = sender as UIElement;

        if (_timer.IsEnabled)
        {
            _timer.Stop();
            Point position = e.GetPosition(element);

            if (Math.Abs(_clickPosition.X - position.X) < 1 && Math.Abs(_clickPosition.Y - position.Y) < 1)
            {
                InvokeActions(null);
            }
        }
        else
        {
            _timer.Start();
            _clickPosition = e.GetPosition(element);
        }
    }

    protected override void OnDetaching()
    {
        base.OnDetaching();

        AssociatedObject.MouseLeftButtonUp -= new MouseButtonEventHandler(AssociatedObject_MouseLeftButtonUp);
        if (_timer.IsEnabled)
            _timer.Stop();
    }

    private void OnTimerTick(object sender, EventArgs e)
    {
        _timer.Stop();
    }
}

InvokeMethodAction:

public class InvokeMethodAction : TargetedTriggerAction<UIElement>
{
    protected override void Invoke(object parameter)
    {
        if (MethodToInvoke != null)
        {
            MethodToInvoke(Target, null);
        }
    }

    public delegate void Handler(object sender, RoutedEventArgs e);
    public event Handler MethodToInvoke;

}

Download sample project here.

Silverlight: DragSelect component

This all started as a requirement for zooming in a chart, then later I decided to make a component out of it – drag select an area.
For the end-user it is really simple: click… select an area by dragging… release!

You can use this anywhere in your application (not only restricted to charts).

It is simple to learn what it does only by playing with my demo.
In seconds you’ll know how to use it: drag-select an area inside the orange rectangle.
All the controls and output are on your left side.

Take a look at the source code to understand more.

Questions and comments are most welcomed.

Demo is here
Source is here

Silverlight: double click a ListBox item

On my previous post i showed how you can attach a double-click event to any Silverlight object.
using this method i’ll show you how to attach a double click event to a ListBox item.

the problem here is that we don’t have any object that we can count on.
i edited the ListBoxItem template, the only change i’ve done is to add a transparent rectangle above all.
look for it inside the template – its name is “DummyRectForDoubleClick”.
then on the Loaded event of this rectangle i attach to it the double click event.

Demo is here
Source is here

Follow

Get every new post delivered to your Inbox.