EventSetter - 在Visual Studio设计错误XAML [英] EventSetter - error XAML in Visual Studio designer

查看:166
本文介绍了EventSetter - 在Visual Studio设计错误XAML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经与XAML做了我的TreeView所有,但现在我想用code-管理背后的事件。该HierarchicalDataTemplate包含一个图像。我需要捕捉事件的MouseEnter /鼠标离开上的图像。我试过这样:

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> 

不过,在Visual Studio的设计出现错误:无法加载文件XAML与EventSetter

But in the designer of Visual Studio appear the error: "Impossible to load a file XAML with EventSetter".

我如何补救? 谢谢! Pileggi

How can I remedy? Thank you! Pileggi

推荐答案

看起来这是一个<一个href="http://social.msdn.microsoft.com/Forums/en/vswpfdesigner/thread/0ecb50c0-d126-44ee-8757-cc1ee292b76e"相对=nofollow>已知的bug 。您可以通过简单的移动风格 EventSetters 来解决它的主资源范围,其中包括它在你的的DataTemplate 的StaticResource

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆