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.
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.
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With