简体   繁体   中英

Why does my C# event fires on XAML (WPF) without running the application?

Just got a very mysterious error while coding a WPF-application in C#.

I've got an event in a custom User-Control, that shows a message box every time the text on a button is changed. When I edit the text on the button in XAML, the event fires - even without my application actually running.

When I tried to open a new WPF-window in the event, the app crashes with "Stackoverflow" - after that, VS (C# Express) crashed too and I wasn't able to open my project until I changed the event and deleted all content in my Debug and Release folders.

Why is this event triggered?

A usercontrol runs inside Visual Studio.

Basically Visual Studio loads the assembly containing the control and executes the control.

This means that if your control shows a message box for some event that is executed at design time, then that message box will be shown in Visual Studio as well.

To fix this, make sure your control doesn't execute harmful or similar code when hosted in Visual Studio.

一些代码仍然可以运行InDesignMode是你的xaml绑定到DataProvider?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM