Why Would a Dependency-Property Implementation Crash My Application When I Provide a Default Value?

后端 未结 1 655
小鲜肉
小鲜肉 2020-12-16 04:37

Why would a dependency-property implementation crash my application when I provide a default value?

This segment of code is in the class declaration for my UserCon

相关标签:
1条回答
  • 2020-12-16 05:27

    Short answer:

    Dependency property default values need to be thread safe (e.g. inherit from System.Windows.Freezable) but System.Windows.Forms.Rectangle isn't.

    Long answer:

    http://social.msdn.microsoft.com/forums/en-US/wpf/thread/2cb12481-ef86-40b7-8333-443598d89933/

    Hint:

    If you are using Visual Studio it really helps to let the IDE break on every exception being thrown. Just go to "Debug" -> "Exceptions" and check "Common Language Runtime Exceptions" "Thrown".

    Then you'll be prompted and get the exception message which in your case looks like this: "Additional information: Default value for the 'Rect' property cannot be bound to a specific thread."

    0 讨论(0)
提交回复
热议问题