y’all. This is a tricky problem that I’ve encountered. I’ve picked up an existing repository with some especially sloppy WPF that doesn’t adhere to MVVM best practices at all. I plan to refactor, but I have near term release targets I want to hit. So, until then, I’m going to follow best practices.
Here’s the rub, if I make any user control, converter, etc, I am unable to reference them in any xaml whatsoever. Suppose I have a window:
<Window … xmlns:views=“clr-namespace:PCXperience.Views” … >
<Window.Resources>
<views:MyUserControl x:Key=“MyUserControl”/>
</Window.Resources>
…
<views:MyUserControl/>
</Window>
```
This is a simple version of the issue. I’ll get xaml errors that the namespace doesn’t exist … it does. And I’ll get an error on the line with the UserControl saying that MyUserControl does not exist in the namespace.
**What I’ve done so far.**
I’ve checked, double checked and triple checked that the namespace is correct. I’ve set the Build Action of the user control to Page and CopyIfNewer. I’ve checked thoroughly that I have the correct Attributes on both the Window and the UserControl. I have cleaned my solution, saved the code, deleted the .vs folder, deleted the obj folder, deleted the bin folder, closed the solution, reopened the solution and done Rebuild Solution. I have even copied the code — everything within the Window and UserControl tabs, their code behinds, and such and pasted into a new repo. The code works in another repo.
**Areas that I suspect**
The declaration attributes of the Window and UserControl could still be wrong somehow though I can’t see it.
The Solution/Project/Etc files could have some error that prevents them from recognizing files in their respective name spaces but it seems to only affect xaml. I can correctly make these in the code behind if I have to, but I don’t want to.
It’s possible some silly issue that I’ve repeatedly overlooked.
I am able to use my resource dictionaries in my project — I just can’t declare new resources in my XAMLs whatsoever.
In an act of what can only be described as a masochistic need for punishment, I wrote this post on my phone. I’ll edit the post to include the top level declarations for each View Element in a moment so we can look at them and see if I’ve missed something obvious. But I am not prepared to type them on my phone here, for the initial post because… I guess that’s where I draw the line, lol.