Attached Behavior and Styles

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

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

I need several presentation lists, all of which will require DoubleClick connected to EditCommand.

Can I embed this behavior in 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>
+5
source share
1 answer

In WPF, you can add a simple setter:

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

Assuming bxmlns is defined in the XAML file that contains your style.

Silverlight, Setters. , Microsoft Silverlight 5.

+3

All Articles