5

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>
4

1 回答 1

3

您应该能够像这样在 WPF 中添加一个简单的 Setter:

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

假设bxmlns 在包含您的样式的 XAML 文件中定义。

但这在 Silverlight 中不起作用,因为在 Setter 中不支持绑定。这是 Microsoft 在Silverlight 5中修复的问题。

于 2011-05-17T16:57:03.790 回答