日历" TargetType与元素“日历"的类型不匹配 [英] Calendar' TargetType does not match type of element 'Calendar'

查看:484
本文介绍了日历" TargetType与元素“日历"的类型不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码出了什么问题,它给出了"DatePicker"异常,TargetType与元素"Calendar"的类型不匹配.

what is wrong in the below code it gives the exception ''DatePicker'' TargetType does not match type of element ''Calendar''.

<Style x:Key="mydate" TargetType="{x:Type DatePicker}">     
    </Style>
    <!--problem code-->
<DataTemplate x:Key="EditingDateTemplate">
        <DatePicker SelectedDate="{Binding DOB}" CalendarStyle="{DynamicResource mydate}" />
    </DataTemplate>

推荐答案

请参阅我对问题的评论.

因此,由于您对问题的表述不令人满意,因此您可能需要一些说明. XAML的问题可能是这样的:引发异常的代码可以自动生成,也可以在您无权访问源代码的库中生成.不用担心:该异常是传播的,您仍然可以跟踪它的原因(它并不总是位于抛出点).

这是捕获所有异常的方法:
当我运行应用程序时,例外是捕获了如何处理此问题? [ throw. .then ... rethrowing [ ^ ].

当某个线程中捕获到异常时,您可以检查或输出Exception.Stack.这只是一个字符串,但是您可以在调用堆栈中找到这些点,至少在您拥有源代码,自己的源代码或在构建过程中自动生成源代码的位置.您应该发布有问题的代码片段,并找到和注释与异常以及其他异常信息有关的行.不要忘记递归地检查Exception.InnerException,因为InnerException也是Exception类型,因此它可以有自己的InnerException.

另外,您可以在调试器中全部运行.实际上,始终应该对运行时行为有丝毫关注,而不仅仅是在遇到异常时.

如果遇到异常,请在抛出异常之前设置一个断点.在调试运行期间,如果暂停执行,请打开调试"窗口调用堆栈".检查一下.您可以单击堆栈中的每个成员.然后您的代码编辑器将打开相应的源代码文件(如果有),然后在代码的相应点选择光标.这样,您可以跟踪导致异常抛出点的所有调用的整个历史记录.此外,您可以在所有异常处理程序上放置断点(实际上,通常应在没有您帮助的情况下将断点保持为绝对最小值,通常为 propagate ,但您可以添加一些代码用于纯粹的调试目的)并跟踪引发异常后传播.

如果经过所有这些调查仍然无法找到解决方案,则可以将获得的信息用于一个真正有用的问题.

这些都是开发人员应具备的基本技能.
我会说,没有这些基本技术就进行任何高级开发几乎没有任何意义.

-SA
Please see my comment to the question.

So, as you your formulation of the question is not satisfactory, you might need some instructions. The problem with XAML can be this: the code where the exception is thrown can be either auto-generated or in the library where you don''t have access to the source code. Not to worry: the exception is propagated and you can track the reason of it (which is not always located at the point of throwing) anyway.

This is how you can catch all exceptions:
When i run an application an exception is caught how to handle this?[^].

See also: throw . .then ... rethrowing[^].

When exception is caught in some thread, you can examine or output Exception.Stack. This is just a string, but you can locate the points in the call stack, at least where you have the source code, your own or auto-generated during build. You should post the code fragments in question and locate and comment the lines related to exception as well as other exception information. Don''t forget to examine Exception.InnerException, recursively, as InnerException is also of the type Exception, so it can have its own InnerException.

Also, you can just run it all under debugger. Actually, you always should do it on the slightest concern about your run-time behaviors, not just when you face exception.

If you run into exception, set a break point just before it was thrown. During debugged run time, when execution is paused, open the Debug window "Call Stack". Examine it. You can click on each member of the stack; and your code editor will open appropriate source code file (if available) and select the cursor at the corresponding point of the code. This way, you can track the whole history of all calls which led to the throw point of the exception. Also, you can put break points on all of the exception handlers (you actually should keep them to absolute minimum as exceptions normally propagate without your help, but you can add some for sheer debugging purposes) and track the propagation of the exception after it has been thrown.

If after all these investigations you still cannot find the solution, you can use the obtained information for a really informative question.

These are all elementary skills any developer should have.
I would say, doing any advanced development without those basic techniques hardly makes much sense.

—SA


看看这个 ^ ],我认为您的类型名称可能不正确.
Take a look at this MSDN entry[^], I think your typename may not be correct.


这篇关于日历" TargetType与元素“日历"的类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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