<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”。请确保不缺少程序集引用,并且已生成所有引用的程序集。为什么报错?

解决方案 »

  1.   

    Student类前面加上public class
      

  2.   

    Student类的代码中
    public class Student
    {
        ...
    }
      

  3.   

     xmlns:xj="clr-namespace:WPF熊俊"
      

  4.   

    检查namespace WPF1
    {
        public class Student
        {
            ...
        }
    }
      

  5.   

    对啊,就是写的xmlns:xj="clr-namespace:WPF熊俊",只是我写错了,但就是报错啊
      

  6.   

    <Window x:Class="WPF熊俊.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:sys="clr-namespace:System;assembly=mscorlib"
            xmlns:xj="clr-namespace:WPF熊俊"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <sys:DateTime x:Key="dt">10/25/2012 4:20 PM</sys:DateTime>
            <xj:Student></xj:Student>
        </Window.Resources>
        <StackPanel>    
        </StackPanel>
    </Window>
    全部代码是这样的,为什么报错呢?
      

  7.   

    如果Student是新添加的,先编译一次。
      

  8.   

    <Window x:Class="WPF熊俊.MainWindow"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:xj="clr-namespace:WPF熊俊"
             Title="MainWindow" Height="350" Width="525">
         <Window.Resources>
             <sys:DateTime x:Key="dt">10/25/2012 4:20 PM</sys:DateTime>
             <xj:Studentt x:Key="st"></xj:Student>
         </Window.Resources>
         <StackPanel>    
         </StackPanel>
     </Window>
    全部代码是这样的,为什么报错呢? 
      

  9.   

    有WPF1空间或者mystudent类么 查看下