我试图将列表绑定到列表框。在 Button1Click 方法中,MyClass 的新实例添加到我的 List<> 中,但在我的列表框中不可见。那里有我的代码:
public static class NotesEngine
{
public static List<Note> All;
static NotesEngine()
{
All = new List<Note>
{
new Note
{
Content = "test1",
}
};
}
public static List<Note> GetNotes()
{
return All;
}
}
这是我的表单集和 ObjectDataProvider:
<ObjectDataProvider ObjectType="{x:Type NotesEngine}" x:Key="NotesList" MethodName="GetNotes"/>
......
<TabItem Header="test" DataContext="{Binding Source={StaticResource NotesList}}">
<ListBox HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
ItemTemplate="{StaticResource NotesListBoxDataTemplate}"
ItemsSource="{Binding }">
</ListBox>
</TabItem>
private void button2_Click(object sender, RoutedEventArgs e)
{
NotesEngine.All.Add(new Note
{
Content = "xx",
Images = new List<string>(),
LastEdit = DateTime.Now,
Title = "XASAC",
});
}
我做错了什么?