ListView + DelegateCommand

Aug 10, 2009 at 12:33 PM

Hi List,

i'm looking for a way to bind a DelegateCommand like : 

public DelegateCommand<object> CommandStartEdit { get; private set; }

<font size="2">



GlobalCommandProxy proxy = new GlobalCommandProxy();

<font size="2" color="#0000ff"><font size="2" color="#0000ff">


</font></font><font size="2" color="#0000ff">



.CommandStartEdit = new DelegateCommand<object>(this.Edit, this.CanEdit);

<font size="2">




to the ListView.SelectionChanged Event of a ListBox.

Any idea's





Aug 10, 2009 at 3:17 PM

Hi Peter,

Out-of-the-box the SelectionChanged event does not support binding to Commands in WPF. To be able to bind to the SelectionChanged event of a ListView in XAML you could create an attached behavior that handles the binding. For this purpose the CommandBehaviorBase<T> was created in prism-v2.

ButtonBaseClickCommandBehavior is an implementation of the CommandBehaviorBase<T> which comes with prism-v2 and you can use as starting point. ButtonBaseClickCommandBehavior is used in Silverlight Applications to support binding commands to the click event. You will find it pretty simple to modify to support the SelectionChanged event.

You might find the following articles useful to implement the attached behavior:

  1. ICommand for Silverlight with Attached Behaviors
  2. another Command with Attached Behavior for the Silverlight 3 DataForm.

Hope it helps!

Matias Bonaventura

Aug 12, 2009 at 5:43 AM

Hi Matias,

your idea works very well.

For others interested in this problem:

Thanks a lot