Type or namespace name 'Ui' does not exist in the namespace when I set a name to a wpf-ui component in xaml
Describe the bug
Hi, I'm using wpf-ui on my wpf app. It's working, but when I write x:name or name to a component in the xaml it gives me the following error: The type or namespace name 'Ui' does not exist in the namespace 'Client.Wpf' (are you missing an assembly reference?) If I cancel the name or x:name the error will go away.
To Reproduce
Set name or x:name to a wpf-ui component.
Expected behavior
x:name in wpf-ui component working
Screenshots
No response
OS version
Windows 11
.NET version
8.0
WPF-UI NuGet version
3.0.4
Additional context
No response
It looks like there is something else in your project whose namespace has *.Client.Wpf.*. Try global::Wpf.Ui or consider changing some names or using's in your files.
It looks like there is something else in your project whose namespace has
*.Client.Wpf.*. Tryglobal::Wpf.Uior consider changing some names orusing's in your files.
How do I set global:Wpf.Ui namespce in xaml? It's working on codebehind, but I need it in xaml for x:Name.
To understand the error, it would be best if you sent the entire code that would allow to reproduce the error.
In xaml:
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
<ui:Button
x:Name="addDeviceBtn"
HorizontalAlignment="Left"
Appearance="Success"
Command="{Binding AddDeviceCommand}"
Content="Add Device"
Cursor="Hand"
Icon="{ui:SymbolIcon Add24}" />
Error CS0234: The type or namespace name 'Ui' does not exist in the namespace 'MyApp.App.Wpf' (are you missing an assembly reference?)
If I remove x:Name the error goes away
In xaml: xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" <ui:Button x:Name="addDeviceBtn" HorizontalAlignment="Left" Appearance="Success" Command="{Binding AddDeviceCommand}" Content="Add Device" Cursor="Hand" Icon="{ui:SymbolIcon Add24}" /> Error CS0234: The type or namespace name 'Ui' does not exist in the namespace 'MyApp.App.Wpf' (are you missing an assembly reference?) If I remove x:Name the error goes away
Would be better full .csproj in zip or repo
In xaml: xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" <ui:Button x:Name="addDeviceBtn" HorizontalAlignment="Left" Appearance="Success" Command="{Binding AddDeviceCommand}" Content="Add Device" Cursor="Hand" Icon="{ui:SymbolIcon Add24}" /> Error CS0234: The type or namespace name 'Ui' does not exist in the namespace 'MyApp.App.Wpf' (are you missing an assembly reference?) If I remove x:Name the error goes away
Would be better full .csproj in zip or repo
Unfortunately I can't share this project..
You don't have to send the project, just the minimal code that causes the error
I ran into this now, with a project being named xyz.Client.Wpf - and also xyz.Client.UI.Wpf - I renamed the project and root namespaces to xyz.Client.Windows (getting rid of the Client and Wpf parts, and it worked.
Try renaming the project so it doesn't end/have .Wpf, same for all the namespaces
renaming the project so it doesn't end/have .Wpf
I was going around in circles for hours until I found this.
I had used 'Appname.Wpf' / Appname.Wpf.csproj and couldn't get a clean compile. Change to Appname.UI and problem solved!
Today, I ran into this bug as well. I cannot rename my projects. Is there a plan for fixing this bug?
This is not WPF-UI issue, but rather how .NET works -- and I really hate partial namespace referencing.
Unfortunately it seems it is not possible to specify global:: in xaml nor in the generated .g.cs files.
When I stumbled upon this issue, I just renamed my csproj to .WpfUI.
This issue should be addressed by MS WPF team rather than pomianowski.
I'm guessing https://github.com/dotnet/wpf/pull/7196 would fix this on the WPF side, but I wouldn't be too optimistic they'll merge that any time soon.
(I tried to use the supplied binary, but it's incompatible with the .NET 10 SDK, and probably would only work with .NET 7. If someone else wants to try it, placing
<PropertyGroup>
<_PresentationBuildTasksAssembly>$(MSBuildProjectDirectory)\PresentationBuildTasks/PresentationBuildTasks.dll</_PresentationBuildTasksAssembly>
</PropertyGroup>
in your csproj and then putting that DLL in a PresentationBuildTasks subdir in your project should do. Someone more adventurous could try building a newer version of the DLL…)