附加行为和样式

5

我使用一个附加行为,使得双击事件可以与视图模型中的命令绑定,如下所示:

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

我需要一个演示中的多个列表框,所有这些列表框都需要一个双击事件与一个编辑命令相关联。

我能把这个行为放到我的MasterListBoxStyle中吗?如何操作?

谢谢,
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>
1个回答

3

在WPF中,您应该能够添加一个简单的Setter,方法如下:

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

假设在包含样式的XAML文件中定义了b xmlns。
但在Silverlight中,这种方式不起作用,因为Setters中不支持绑定。这是微软在Silverlight 5中正在修复的问题。

我本来想尝试一下,但是我自己想了想,“算了,太简单了” :--) - Berryl

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接