Silverlight doesn't contain a Command button like the Button in WPF. The way we get around it there is to create a custom control that contains a command and maps that event to the command. Something like this should work.
public class CommandListBoxItem : ListBoxItem
{
public CommandListBoxItem()
{
DoubleClick += (sender, e) =>
{
if (Command != null && Command.CanExecute(CommandParameter))
Command.Execute(CommandParameter);
};
}
#region Bindable Command Properties
public static DependencyProperty DoubleClickCommandProperty =
DependencyProperty.Register("DoubleClickCommand",
typeof(ICommand), typeof(CommandListBoxItem),
new PropertyMetadata(null, DoubleClickCommandChanged));
private static void DoubleClickCommandChanged(DependencyObject source, DependencyPropertyChangedEventArgs args)
{
var item = source as CommandListBoxItem;
if (item == null) return;
item.RegisterCommand(args.OldValue as ICommand, args.NewValue as ICommand);
}
public ICommand DoubleClickCommand
{
get { return GetValue(DoubleClickCommandProperty) as ICommand; }
set { SetValue(DoubleClickCommandProperty, value); }
}
public static DependencyProperty DoubleClickCommandParameterProperty =
DependencyProperty.Register("DoubleClickCommandParameter",
typeof(object), typeof(CommandListBoxItem),
new PropertyMetadata(null));
public object DoubleClickCommandParameter
{
get { return GetValue(DoubleClickCommandParameterProperty); }
set { SetValue(DoubleClickCommandParameterProperty, value); }
}
#endregion
private void RegisterCommand(ICommand oldCommand, ICommand newCommand)
{
if (oldCommand != null)
oldCommand.CanExecuteChanged -= HandleCanExecuteChanged;
if (newCommand != null)
newCommand.CanExecuteChanged += HandleCanExecuteChanged;
HandleCanExecuteChanged(newCommand, EventArgs.Empty);
}
private void HandleCanExecuteChanged(object sender, EventArgs args)
{
if (DoubleClickCommand != null)
IsEnabled = DoubleClickCommand.CanExecute(DoubleClickCommandParameter);
}
}
Then when you create your ListBoxItems you bind to the new Command Property.
<local:CommandListBoxItem DoubleClickCommand="{Binding ItemDoubleClickedCommand}" />