若想在UserControl上面的事件管用,则Background不能为Null,而UserControl默认的Background为Null,所以导致鼠标事件不起作用,而Window默认Background是不为Null的,所以也就支持各种事件。
<!--此Grid区域内的MouseEnter事件不起作用-->
<Grid Height="490" Width="410" ><i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<i:InvokeCommandAction Command="{Binding CommandMouseEnterImgData}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Grid>
<!--此Grid区域内的MouseEnter事件起作用-->
<Grid Height="490" Width="410" Background="Transparent">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<i:InvokeCommandAction Command="{Binding CommandMouseEnterImgData}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Grid>