我有一个风格,我希望将命令绑定到EventSetter的Handler用RelativeSource.该命令位于viewModel中.
<Style x:Key="ItemTextBlockEventSetterStyle" TargetType="{x:Type TextBlock}">
<EventSetter Event="MouseLeftButtonDown"
Handler="{Binding TextBlockMouseLeftButtonDownCommand,
RelativeSource={RelativeSource Self}}"/>
</Style>
Run Code Online (Sandbox Code Playgroud)
问题是我得到一个错误,因为这有什么问题(也许不可能以这么简单的方式做到这一点)
我之前搜索了很多,我发现了AttachedCommandBehaviour,但我认为它不适用于风格.
你能给出一些如何解决这个问题的提示吗?
更新13/10/2011
我在MVVM Light Toolkit EventToCommand示例程序中找到了这个:
<Button Background="{Binding Brushes.Brush1}"
Margin="10"
Style="{StaticResource ButtonStyle}"
Content="Simple Command"
Grid.Row="1"
ToolTipService.ToolTip="Click to activate command">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cmd:EventToCommand Command="{Binding SimpleCommand}" />
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeave">
<cmd:EventToCommand Command="{Binding ResetCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
Run Code Online (Sandbox Code Playgroud)
但在这里,绑定不是风格.我怎么能把它放到EventToCommand按钮的样式?
我有一个GridView,我想在列表中的项目上检测doubleclick事件,我按如下方式执行:
<ListView>
<ListView.View >
<GridView >
<GridViewColumn Header="FileName">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding FileName}" MouseDoubleClick="Configuration_MouseDoubleClick"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding CreationDate}" Header="Date"/>
</GridView>
</ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud)
问题是我只能通过将双击附加到模板中的控件来检测双击.
我怎样才能把这MouseDoubleClick件事附加到整体上ListViewItem?PRISM有没有解决方案?