我已经使用 XAML 完成了 TreeView,但现在我想使用隐藏代码来管理事件。 HierarchicalDataTemplate 包含一个图像。我需要捕获图像上的 MouseEnter / MouseLeave 事件。我已经尝试过这样的方式:
<Image x:Name="imgArticolo" Source="{Binding imgArt}">
<Image.Style>
<Style TargetType="{x:Type Image}">
<EventSetter Event="MouseEnter" Handler="iArt_MouseEnter"/>
</Style>
</Image.Style>
</Image>
但在 Visual Studio 的设计器中出现错误:“无法使用 EventSetter 加载文件 XAML”。
我该如何补救?
谢谢你!
皮莱吉
看起来这是一个已知错误 http://social.msdn.microsoft.com/Forums/en/vswpfdesigner/thread/0ecb50c0-d126-44ee-8757-cc1ee292b76e。您可以通过简单地移动Style
with EventSetters
到主要Resources
范围并将其包含在您的DataTemplate
as a StaticResource
:
<Style x:Key="myImageStyle" TargetType="{x:Type Image}">
<EventSetter Event="MouseEnter" Handler="iArt_MouseEnter"/>
</Style>
<HierarchicalDataTemplate x:Key="modTreeArtDataParts2">
<Grid>
<Border x:Name="bdArt">
<Image x:Name="imgArticolo" Source="{Binding imgArt}" Height="Auto"
Style="{StaticResource myImageStyle}" />
</Border>
</Grid>
</HierarchicalDataTemplate>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)