我得到一个XAMLParseException,它真的覆盖了另一个异常。这里是堆栈跟踪的一部分:
Message=Object reference not set to an instance of an object.
Source=AssignmentOrganizer
StackTrace:
at AssignmentOrganizer.MainWindow..ctor() in C:\Users\Mohit\Documents\Visual Studio 2010 \Projects\AssignmentOrganizer\AssignmentOrganizer\MainWindow.xaml.cs:line 29
这里是第29行:对象引用未设置为对象存储库的实例
lvwMain.ItemsSource = _assignmentRepo.ListAssignments();
凡lvwMain是ListView和_assignmentsRepo是一种IAssignmentRepository声明如下:
IAssignmentRepository _assignmentRepo;
这就是错误发生。我正在使用存储库模式任何人都愿意猜测?
这是我的XAML:
<Window x:Class="AssignmentOrganizer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="MainWindow" Height="518" Width="755">
<DockPanel>
<Menu DockPanel.Dock="Top">
</Menu>
<ToolBar DockPanel.Dock="Top">
</ToolBar>
<StatusBar DockPanel.Dock="Bottom">
</StatusBar>
<Grid DockPanel.Dock="Left" Width="150">
<Grid.RowDefinitions>
<RowDefinition Height="259*" />
<RowDefinition Height="259*" />
</Grid.RowDefinitions>
</Grid>
<Grid DockPanel.Dock="Right" Width="150">
</Grid>
<Grid>
<ListView x:Name="lvwMain">
<ListView.View>
<GridView>
<GridViewColumn Header="Title" Width="125" />
<GridViewColumn Header="Due" Width="75" />
</GridView>
</ListView.View>
</ListView>
</Grid>
</DockPanel>
我试着将它分配给AssignmentRepository。但是_assignmentRepo并不是空的,因为我从断点中学到了东西。 – 2010-01-24 01:27:06
如果我删除了设置listview项目源的代码行,代码运行得很好。 – 2010-01-24 03:17:45
@Mohit Deshpande:如果你确定你已经分配了'_assignmentRepo',那么你还需要检查'lvmMain'。 – jason 2010-01-24 20:42:46