尝试创建UserControl的实例时,获取NullPointerException

时间:2012-11-03 09:19:45

标签: c# wpf visual-studio-2010 visual-studio-2008 user-controls

当我尝试使用同一解决方案中的UserControl时,我会在NullPointerException行中获得InitializeComponent()

我的MainWindow.xaml.cs文件,我正在添加UserControl

ViewStudentUc viewStudentUc = new ViewStudentUc();
viewStudentGrid.Children.Add(viewStudentUc);

我的ViewStudentUc.xaml文件,我得到例外:

public ViewStudentUc()
{
    InitializeComponent();   //Where I'm getting NullPointerException.
}

为什么我会收到此异常,如何将其删除?

这是调用堆栈。

SNS School Management.exe!SNS_School_Management.ViewStudentUc.ViewStudentUc() Line 25   C#
SNS School Management.exe!SNS_School_Management.MainWindow.viewStudent_button_Click(object sender, System.Windows.RoutedEventArgs e) Line 39 + 0x15 bytes   C#
[External Code] 

0 个答案:

没有答案