Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The XAML designer has stopped using the design-time data context

In my project, I have several WPF windows and controls. For each one, I've created a sample view model so I can see the window or control mocked-up with sample data in the XAML designer by including a line like this:

         d:DataContext="{x:Static views:SampleViewModels.SampleVariableViewModel}"

That has worked great for years. However, sometime today, or possibly yesterday, the XAML designer stopped showing sample data on my computer. Every view, in both current and old revisions of code, is shown without the data from its sample view model. I've rebuilt the project, restarted Visual Studio, and rebooted the computer, to no effect. This problem affects only me; my colleagues see the sample data properly.

Importantly, the XAML designer is showing some data, just not the right data. When a field is bound to "Name", for instance, the designer is using the text "Name". Numbers are (sometimes?) filled-in with 0. And where my view model has a collection, the designer shows me 3 elements. It is as if something is creating a very crude sample view model and using it instead of my carefully prepared sample view model.

Note that other than ignoring my sample data, the XAML designer is working fine. And everything works perfectly at runtime.

Is there any known "feature" of Visual Studio that could be doing this? Might I have accidentally hit some key combination that turned on some little-known XAML designer mode?

I'm using Visual Studio Community 2015. I've disabled Resharper, and I don't think I'm using any other extension that could do something like this. Any ideas?

Update: I deleted everything from the ShadowCache folder. That didn't help.

Update: I installed Visual Studio Community 2017. Everything works properly in that version, but still doesn't work in Visual Studio Community 2015.

like image 968
Lork Avatar asked Apr 26 '17 21:04

Lork


People also ask

How do I enable XAML designer?

To open the XAML Designer, right-click a XAML file in Solution Explorer and choose View Designer. to switch which window appears on top: either the artboard or the XAML editor.

How do I disable XAML designer?

You can disable the XAML designer using the Options dialog box. To do so, open the dialog by selecting the Options item from the Tools menu. Once visible, expand the "Text Editor" section, then the "XAML" section at the left of the dialog box. Select "Miscellaneous" to show the correct options.


2 Answers

I had exactly the same issue with VS 2017. I figured out that I accidentally unchecked the disable project code option in the XAML designer. After activating this option the value from my resource file was displayed again. See this screenshot:

Microsoft Visual Studio: disable project code

like image 157
Philippe Avatar answered Oct 13 '22 04:10

Philippe


Previously provided answer is correct, but there is also another correct answer: If you are compiling for X64 or ARM (as opposed to AnyCPU or x86, for example) then "Disable project code" is always in effect and you can't turn it off. Even Visual Studio 2019 does not support running ARM or X64 code in the designer it seems.

like image 29
Ammo Goettsch Avatar answered Oct 13 '22 03:10

Ammo Goettsch