本文介绍了EventSetter - Visual Studio设计器中的XAML错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经用XAML完成了我的TreeView,但是现在我想用代码隐藏来管理一个事件。 HierarchicalDataTemplate包含一个图像。我需要捕获图像上的MouseEnter / MouseLeave事件。我以这种方式尝试过: < Image x:Name =imgArticoloSource ={Binding imgArt} >
< Image.Style>
< Style TargetType ={x:Type Image}>
< EventSetter Event =MouseEnterHandler =iArt_MouseEnter/>
< / Style>
< /Image.Style>
< / Image>
但在Visual Studio的设计器中出现错误:不可能使用EventSetter加载文件XAML 。
我如何补救?
谢谢!
Pileggi
解决方案
< Style x:Key =myImageStyleTargetType ={x:Type Image}>
< EventSetter Event =MouseEnterHandler =iArt_MouseEnter/>
< / Style>
< HierarchicalDataTemplate x:Key =modTreeArtDataParts2>
< Grid>
< Border x:Name =bdArt>
< Image x:Name =imgArticoloSource ={Binding imgArt}Height =Auto
Style ={StaticResource myImageStyle}/>
< / Border>
< / Grid>
< / HierarchicalDataTemplate>
I've done my TreeView all with XAML but now I'd like to manage an event with code-behind. The HierarchicalDataTemplate contains an Image. I need to capture the events MouseEnter / MouseLeave on the Image. I've tried in this way:
<Image x:Name="imgArticolo" Source="{Binding imgArt}">
<Image.Style>
<Style TargetType="{x:Type Image}">
<EventSetter Event="MouseEnter" Handler="iArt_MouseEnter"/>
</Style>
</Image.Style>
</Image>
But in the designer of Visual Studio appear the error: "Impossible to load a file XAML with EventSetter".
How can I remedy?Thank you!Pileggi
解决方案
It looks like this is a known bug. You may be able to resolve it by simply moving the Style
with EventSetters
to the main Resources
scope and including it in your 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>
这篇关于EventSetter - Visual Studio设计器中的XAML错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!