The name does not exist in the namespace in WPF application

℡╲_俬逩灬. 提交于 2020-02-05 06:54:33

问题


Creating a WPF application, using VS2017. I have an enum like:

namespace Sample.Common
{
    public enum SmPageTypes
    {
        Type1 = 0,
        Type2 = 1
    }
}

I'm trying to use it in xaml form, but get an error:

The name "SmPageTypes" does not exist in the namespace "clr-Sample.Common;assembly=Sample".

Here is xaml code adding namespace:

xmlns:CommonAlias="clr-namespace:Sample.Common;assembly=Sample"

and add enum as resource:

<Window.Resources>
    <ObjectDataProvider x:Key="dataFromEnum" MethodName="GetValues"
                        ObjectType="{x:Type System:Enum}">
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="CommonAlias:SmPageTypes" />
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
</Window.Resources>

I've added the project, containing this enum, tried to clean, restart Visual Studio, rebuild solution with administrator rights, changed platform target and configuration, it did not help. What else can I do?


回答1:


If the enum and the XAML are in different projects, the project containing the XAML must have a reference to the one containing the enum.

Right-click the XAML project, select Add reference, and add a reference to your enum project.




回答2:


I've solved the problem. The reason was that assembly name should be Sample.Common, not Sample.




回答3:


In VS, right click on your Solution -> Properties -> Configuration Properties

A new dialog is opened, try to change the project configurations from Debug to Release or vice versa.

After that, re-build your solution. It can solve your problem



来源:https://stackoverflow.com/questions/51408156/the-name-does-not-exist-in-the-namespace-in-wpf-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!