Question

I use an attached behavior that allows a DoubleClick event to be wired to a command in a view model, as in the binding below:

<ListBox Style="{StaticResource MasterListBoxStyle}"
    b:SelectionBehavior.DoubleClickCommand="{Binding EditCommand}" 
     >

I need multiple list boxes for a presentation, all of which will need a DoubleClick wired to an EditCommand.

Can I push this behavior into my MasterListBoxStyle? How?

Cheers,
Berryl

<Style x:Key="MasterListBoxStyle" TargetType="ListBox">
    <Setter Property="ItemsSource" Value="{Binding MasterVm.AllDetailVms}" />
    <Setter Property="ItemContainerStyle" Value="{StaticResource MasterListingRowStyle}" />
    <Setter Property="IsSynchronizedWithCurrentItem" Value="True" />
    <Setter Property="AlternationCount" Value="2" />
</Style>
Was it helpful?

Solution

You should be able to add a simple Setter like so in WPF:

<Setter Property="b:SelectionBehavior.DoubleClickCommand" Value="{Binding EditCommand}" />

Assuming the b xmlns is defined in the XAML file that contains your Style.

This won't work in Silverlight though, since Bindings are not supported in Setters. This is something Microsoft is fixing in Silverlight 5.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top