想象我有一個實體:實體框架和綁定同步
public class MyObject
{
public string Name { get; set; }
}
而且我有一個列表框:
<ListBox x:Name="lbParts">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我把它綁定到後臺代碼的集合:
ObjectQuery<MyObject> componentQuery = context.MyObjectSet;
Binding b = new Binding();
b.Source = componentQuery;
lbParts.SetBinding(ListBox.ItemsSourceProperty, b);
然後點擊一個按鈕,我將一個實體添加到MyObjectSet中:
var myObject = new MyObject { Name = "Test" };
context.AddToMyObjectSet(myObject);
以下是問題 - 此對象需要在UI中更新爲。但它不添加有:(
請參閱http://stackoverflow.com/questions/7528400/ef-code-first-binding-to-listbox/7532473#7532473 – juFo