Jazzschmidt
Jazzschmidt

Reputation: 1105

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?

Upvotes: 1

Views: 415

Answers (2)

Joseph Le Brech
Joseph Le Brech

Reputation: 6653

Some code can still run InDesignMode is your xaml bound to a DataProvider?

Upvotes: 0

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391276

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.

Upvotes: 4

Related Questions