当用户双击我的ItemsControl的Item时,我想绑定命令的调用。
所以我使用了System.Windows.Interactivity(v3.5):
<ItemsControl ItemsSource="{Binding AllFiles, Mode=OneWay}">
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type viewModel:FolderVM}">
<DockPanel Margin="5" Height="70" Width="300">
<DockPanel.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextWrapping" Value="WrapWithOverflow"/>
</Style>
</DockPanel.Resources>
<i:Interaction.Triggers>
<!--Exception:Cannot add content of type 'System.Windows.Interactivity.EventTrigger' to an object of type 'System.Windows.Interactivity.TriggerCollection'.-->
<i:EventTrigger EventName="MouseDown">
<i:InvokeCommandAction CommandName="CmdBrowseFolder"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Image Height="70" Width="70" DockPanel.Dock="Left" Source="{Binding Icon}"/>
<Grid Background="LightBlue" DockPanel.Dock="Left">
<WrapPanel Margin="10,0,0,0" Orientation="Vertical">
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="Folder"/>
</WrapPanel>
</Grid>
</DockPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type viewModel:FileVM}">
<DockPanel Margin="5" Height="70" Width="300">
<DockPanel.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextWrapping" Value="WrapWithOverflow"/>
</Style>
</DockPanel.Resources>
<Image Height="70" Width="70" DockPanel.Dock="Left" Source="{Binding Icon}"/>
<Grid Background="LightBlue" DockPanel.Dock="Left">
<WrapPanel Margin="10,0,0,0" Orientation="Vertical">
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="{Binding SizeFormatted}"/>
</WrapPanel>
</Grid>
</DockPanel>
</DataTemplate>
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
但是,一旦我运行应用程序,就会触发以下异常:无法添加类型&System; Windows.Windows.Interactivity.EventTrigger&#39;到#System; Windows.Windows.Interactivity.TriggerCollection&#39;类型的对象。
编辑:更多信息:
当我用InvokeCommandAction注释该行时不再有异常。但当然事件并没有触发命令
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDown">
<!--<i:InvokeCommandAction CommandName="CmdBrowseFolder"/>-->
</i:EventTrigger>
</i:Interaction.Triggers>
另一个信息:版本3.5中的InvokeCommandAction不包含Command DP,只包含CommandName和CommandParameter
答案 0 :(得分:0)