日期:2014-05-17  浏览次数:20853 次

WPF,这样使用本项目的命名空间为什么不对?
<Window x:Class="WPF熊俊.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:xj="clr-namespace:WPF1"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <xj:Student x:Key="mystudent" age="25"></xj:Student>
    </Window.Resources>
    <StackPanel>  
    </StackPanel>
</Window>


上面的代码,引用了本项目的名称空间,本项目有个Student类,但为什么实例化的时候,要报错呢:未到类型“xj:Student”。请确保不缺少程序集引用,并且已生成所有引用的程序集。

为什么报错?

------解决方案--------------------
Student类前面加上public class
------解决方案--------------------
Student类的代码中
public class Student
{
    ...
}
------解决方案--------------------
 xmlns:xj="clr-namespace:WPF熊俊"
------解决方案--------------------
有WPF1命名空间吗
------解决方案--------------------
检查

namespace WPF1
{
    public class Student
    {
        ...
    }
}
------解决方案--------------------
如果Student是新添加的,先编译一次。