确保Wpf中的事件失败 [英] Ensure Event Failed in Wpf

查看:924
本文介绍了确保Wpf中的事件失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:CustomCalc">
    <Style TargetType="{x:Type local:CustomControl1}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:CustomControl1}">
                    
                    <TextBlock Text="welcome" Height="50" Width="150" MouseDown=""/>
                    
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>





在上面的程序中,我尝试添加一个事件对于文本块,它会给出错误消息确保事件失败,请提前解释为什么会发生以及如何解决它。提前感谢。



in the above program, i try to add a event to textblock it gives a error message "ensure event failed", please explain why it should occur and how to resolve it, thanks in advance.

推荐答案

Y您必须将以下属性添加到第一个标记( ResourceDictionary ):

You have to add the following attribute to the first tag (ResourceDictionary):
x:Class="YourNamespace.YourClass"


这个错误是因为视图中的命名空间与命名空间代码隐藏不同,例如:



错误的形式:



查看:x:clase =Example.MyView



CODEBEHIND:namespace Example2.MyView



正确形式:



查看:x:clase =Example.MyView



CODEBEHIND:名称空间Example.MyView
This error ocurre because the namespace in the view is diferent to the namespace codebehind, example:

Wrong form:

VIEW: x:clase="Example.MyView"

CODEBEHIND: namespace Example2.MyView

Correct form:

VIEW: x:clase="Example.MyView"

CODEBEHIND: namespace Example.MyView


这篇关于确保Wpf中的事件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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