How to manually reload the Visual Studio designer for WPF

Viewed 28216

Is there any way to force the WPF designer to reload or refresh, without rebuilding the entire project or solution?

If there's an error, I get an option in the designer view to refresh the designer. But if I don't have an error, how can I get the designer to refresh after I've made a change?

11 Answers

The Visual Studio designer attempts to keep the rendered view in sync with the XAML. That's the advertised behavior.

  • The first thing you should check is that there are no errors in the errors window. It may be something as simple as a missing angle bracket.
  • The second thing to check is whether you have any code (other than your code-behind) which needs to be compiled for the designer to render your XAML correctly. This includes any of your own datatypes that you instantiate in XAML, any custom controls you have written (e.g. MyTextBlock derived from TextBlock), or any classes directly or indirectly in support of design-time data. If so, you need to rebuild your project.
  • The last thing to check for is possible bugs in the designer. In spite of the advertised behavior, the designer may get out-of-sync due to bugs. In that close, close the XAML window and re-open it. Other tricks that might work are selecting the XAML tab and then the Design tab, or maximizing the XAML pane.

As far as rebuilding your application goes, you don't need to do this as a habit. You only need to recompile it when the above conditions apply. Once they don't apply, you can just edit the XAML. Another way to say this is that if you haven't modified code, you shouldn't need to rebuild (modulo bugs).

I'm not sure, but I think a build will refresh your view in that situation.

There is any event handled in that XAML file, then mostly it will not display the design preview from Visual Studio. If you want to see the design from Visual Studio, try with Command Binding instead of event, you will see the preview.

I'm not sure how this works in WPF editing, but with ASP.NET pages when the design view wont update i can do 2 things

  1. Exit Visual Studio and restart
  2. Go into source view (not split), type something and remove it (not by undoing, just delete or backspare) and save it. Then return to design view, usually the view has been updated then.

On the toolbar in the XAML designer, choose the "Disable project code" button to reload the designer link which stays on the right side of "Turn on snapping to snaplines".

Disable project code in the designer

If it is disabled, you can try to check the configuration manager and change processors to "Any CPU".

For projects that target ARM or X64 processors, Visual Studio cannot run project code in the designer, so the Disable project code button is disabled in the designer. Check this:

Debug or disable project code in XAML Designer

For information, I had the same issue with the XAML Designer of Visual Studio Community 2017, i.e. sometimes the designer doesn't show anything, the easiest solution is then to close the XAML file and reopen it.

I also frequently get the exception "An Unhandled Exception has occurred - Click here to reload the designer - Details: The XAML Designer has exited unexpectedly" (the click restarts the designer successfully).

Note that, in this VS version, the process of the XAML designer is not named XDesProc.exe, but UwpSurface.exe. If you prefer or have to kill the process, then the designer shows the same exception as above, and you may restart it.

use process hacker and kill the WpfSurface process (blend only)

Related