How can I debug at design time?
Asked Answered
S

2

17

I created a custom ListView with a UserControl. When the mouse enters the ColumnHeader it should change color at design time.

It works, but I need to debug code. How can I debug code at design time?

Example image

Scaremonger answered 24/6, 2011 at 7:29 Comment(0)
C
24

See Walkthrough: Debugging Custom Windows Forms Controls at Design Time (MSDN).

Or in a shorter way to do it just once:

  • Start Visual Studio twice with the same solution.
  • The first with an opened designer of your control, the second to attach by using menu ToolsAttach to Process → the other devenv.exe (Visual Studio)
Chyme answered 24/6, 2011 at 7:51 Comment(3)
The designer gives an error but nothing happens on the other VS that was supposed to be debugging.Jenelljenelle
Update link for VS2017: learn.microsoft.com/en-us/dotnet/framework/winforms/controls/…Adanadana
For VS2017 path is: %ProgramFiles(x86)%\Microsoft Visual Studio\2017\<edition>\Common7\IDEOutofdoors
G
1

Kelon's answer is correct for Windows Forms, but not for XAML.

In Visual Studio 2012 and later, the XAML designer runs in its own process outside Visual Studio (devenv.exe). To debug XAML controls at design time you need to attach the second instance of Visual Studio to 'XDesProc.exe' (Xaml Designer Process).

Detailed instructions:

  • Open Visual Studio with the solution containing your XAML to be debugged
  • Open any XAML file (so XDesProc will start)
  • Make a note of the XDesProc.exe process ID using: menu ToolsAttach to Process, scroll down and note the process ID. (Do not actually attach or Visual Studio will hang.)
  • Close the XAML file
  • Open a second instance of Visual Studio with the same solution
  • Menu ToolsAttach to Process, and attach to the XDesProc process you noted above

    Attach to XDesProc

  • If you are debugging an exception, menu DebugWindowsException Settings, Common Language Runtime Exceptions → checked

    Debug Windows Exception Settings

    Common Language Runtime Exceptions

  • Go back to the first instance and re-open the XAML file.

  • The second instance of Visual Studio will break at the exception
  • You can also set breakpoints in the second instance
  • To recompile after you have fixed the bug you must stop debugging
  • To debug again you can save time by doing menu DebugReattach to process, which attaches to the same XDesProc.exe as before.

    Reattach

Gains answered 4/7, 2018 at 16:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.