Search code examples
c#wpfxamlxaml-designer

Why is the WPF Designer not picking up my code changes to my Control Library at design time?


I have a control library with xaml and view models for the xaml. They are loaded by a separate App exe project. I changed a view model class in my library project to have a no-args constructor to allow some design-time rendering of items. I then built the control library project and it rendered, but without the design-time data. On the line with d:DataContext="{d:DesignInstance Type=local:MyViewModel, IsDesignTimeCreatable=False}" the editor highlights the line with No parameterless constructor defined. However, I have defined the constructor with 0 parameters and rebuild the library. If I create a new ViewModel class to test with it will autocomplete the class name with intellisense, but then show an error Could not load type 'MyNamespace.MyViewModelTest' from assembly 'MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Why is the designer not picking up these changes?


Solution

  • The issue is that you must build the application project, not just the control library project.

    This may seem odd at first because if your control library has no other dependencies, but the Visual Studio designer is trying to be helpful in detecting styles and themes from your main application's App.xaml in the main application project. It understands that even though there is no direct dependency from your control library to the main app project, there are implicit resources that may be shared (resources in App.xaml and themes).

    Visual Studio 2022 uses a designer process called SurfaceApp.exe that will pull your dlls from your Application project's output folder (typically under bin) if there is one, not the control library's output folder. That means you must build from your Application project, not the control library, to update what the designer sees.