RLH
RLH

Reputation: 15698

Within the WPF Designer, what does Enabling/Disabling Project Code do?

I have no clue how long this feature/option has been around but my mouse happened to pause over this button within the WPF designer early and now I'm curious what it's purpose is.

enter image description here

Hovering over the button, Visual Studio pops up a tooltip that says Enable project code. When I click on it, the designer seems to reload the xaml contents but I can't tell what's changed.

What does this feature do?

2020 EDIT

It's been years since I've had to work in XAML, but I've received a new project where I need to work in XAML. This feature/button seems to have disappeared. Where has it migrated?

Upvotes: 9

Views: 3502

Answers (2)

Hemendr
Hemendr

Reputation: 1060

In Visual Studio 2022, the text of this option is changed to "Display all controls / Only Display Platform Controls" while the purpose is still to disable project code in the designer.

To see how it affects the display of controls in XAML Designer you can create a sample project containing one custom control like I created a custom data grid with coloured columns.

When you choose the option "Display all controls" then your data grid is rendered in XAML design view, however, if you "choose Only Display Platform Controls" and as mentioned on MSDN website

When you select Only Display Platform Controls, all custom controls coming from SDKs, customer user controls, and more, will not render completely. Instead, they are replaced by fallback controls to demonstrate the size and position of the control.

enter image description here

Upvotes: 0

mm8
mm8

Reputation: 169360

What does this feature do?

It enables or prevents the designer from running your code in the background.

Disabling project code can lead to a loss of design time data and enabling it can lead to unhandled exceptions in the XAML designer. These exceptions are usually caused by code that attempts to access properties or methods which work differently when your application is running in the designer compared to when it runs as a built executable.

Debugging or Disabling Project Code in XAML Designer: https://msdn.microsoft.com/en-us/library/mt622752.aspx?f=255&MSPPError=-2147217396

Upvotes: 8

Related Questions