我想從使用MVVMWPF MVVM databing到DataGrid中沒有更新
在WPF的DataGrid對象顯示的筆記列表XAML:
<DataGrid
x:Name="NoteGrid"
ItemsSource="{Binding NoteObj.Notes}"
SelectedItem="{Binding CurrentNote}"
AutoGenerateColumns="False"
CanUserAddRows="False"
CellEditEnding="DataGrid_CellEditEnding">
<DataGrid.Columns>
<DataGridTextColumn Header="Note" Binding="{Binding NoteText}" />
<DataGridTextColumn Header="Type" Binding="{Binding Type.Name}" />
</DataGrid.Columns>
</DataGrid>
NoteObj.Notes的返回值是EntitySet的。
視圖模型:
private NoteObject noteObj;
public NoteObject NoteObj
{
get { return noteObj; }
set { noteObj = value; OnPropertyChanged("NoteObj"); }
}
public void AddNote()
{
var note = new Note
{
NoteText = "Note text",
NoteType = 1
};
NoteObj.Notes.Add(note);
DC.SubmitChanges();
OnPropertyChanged("NoteObj");
}
當NoteObj設置充滿了音符,但AddNote法不wotk DataGrid中! 新筆記已添加到數據庫,但DataGrid永遠不會更新。
這是一個問題eith EntitySet或我在XAML中丟失了什麼?
嘗試添加[presentationtracesources](http://msdn.microsoft.com/zh-cn/library/system.diagnostics.presentationtracesources.tracelevel.aspx)並查看它是否在輸出中提供了一些提示。 – Vegar
如果我將TraceLevel設置爲「高」或「中」,則程序在SubmitChanges(行未找到或某物)上崩潰。沒有輸出! –
這可能表明EF有問題,而不是綁定? – Vegar