【发布时间】:2017-06-04 01:28:54
【问题描述】:
我遇到了一个奇怪的问题(Visual Studio 2012):
“命名空间‘XX.X’中不存在类型或命名空间名称‘X’(您是否缺少程序集引用?)...\MyUserControl.g.cs ....
我有以下用户控制:
<UserControl x:Class="xxxxxx.MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<StackPanel>
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Path=h}" FontWeight="Bold" FontSize="12" Foreground="Black" />
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Path=hd}" FontSize="12" Margin="10,10,0,5" MaxWidth="250" TextWrapping="Wrap" Height="Auto" Foreground="Black"/>
</StackPanel>
</UserControl>
当我尝试构建项目时,.g.cs 文件坚持添加引用中不存在的命名空间,并且不要在 xaml 中以任何方式使用它。
我试图进行清洁和重建.. 没有任何帮助。
通常这样的问题是命名空间写不正确的时候,但是这里我没有引用任何其他命名空间,所以很奇怪。
还有其他人遇到此问题并可以提供帮助吗?
【问题讨论】:
-
尝试将 UserControl 的内容复制到剪贴板,删除 UserControl,创建一个新的并粘贴剪贴板中的内容。对您可能拥有的任何代码隐藏执行相同的操作。并关闭 .g.cs 文件。并重建。
-
@mm8 我试过了,也没有用:(
-
您应该检查您的 XAML 中是否定义了一些命名空间,这些命名空间引用了这个无法识别的程序集。
-
您的 XAML 代码在我看来很完美,只需做一件事创建一个新项目并尝试再次构建它
-
可能在“Styles.xaml”或“Generic.xaml”中。您是否尝试过“在文件中查找”?
标签: c# wpf visual-studio namespaces