我有一個視圖,顯示綁定到GETALL()列表框:)如何獲得一個ItemsSource刷新其綁定?
<DockPanel>
<ListBox ItemsSource="{Binding GetAll}"
ItemTemplate="{StaticResource allCustomersDataTemplate}"
Style="{StaticResource allCustomersListBox}">
</ListBox>
</DockPanel>
GETALL(被一個ObservableCollection財產在我的視圖模型:
public ObservableCollection<Customer> GetAll
{
get
{
return Customer.GetAll();
}
}
這反過來調用GETALL()模型方法讀取XML文件以填充的ObservableCollection:
public static ObservableCollection<Customer> GetAll()
{
ObservableCollection<Customer> customers = new ObservableCollection<Customer>();
XDocument xmlDoc = XDocument.Load(Customer.GetXmlFilePathAndFileName());
var customerObjects = from customer in xmlDoc.Descendants("customer")
select new Customer
{
Id = (int)customer.Element("id"),
FirstName = customer.Element("firstName").Value,
LastName = customer.Element("lastName").Value,
Age = (int)customer.Element("age")
};
foreach (var customerObject in customerObjects)
{
Customer customer = new Customer();
customer.Id = customerObject.Id;
customer.FirstName = customerObject.FirstName;
customer.LastName = customerObject.LastName;
customer.Age = customerObject.Age;
customers.Add(customer);
}
return customers;
}
這一切工作正常,當用戶進入到另一種觀點認爲EXCEPT,編輯XML文件,回來這一觀點,其中舊數據仍呈現。
我怎樣才能知道這個觀點「刷新其綁定」,使其顯示實際數據。
感覺就像我在這裏用WPF過多的HTML/HTTP隱喻一樣,我覺得有一種更自然的方式來獲取ObservableCollection來更新自己,因此它的名字,但這是我唯一的方法可以讓用戶能夠在此刻編輯WPF應用程序中的數據。所以在這裏,任何級別的幫助都會被讚賞
我改變GETALL()來GETALL,謝謝。問題是我有兩個視圖,它們分別從各自的ViewModel中獲取單獨的GetAll ObservableCollection,當一個ObservableCollection發生更改時,另一個不會更改。我需要將這些地點存儲在全球嗎? – 2009-04-30 13:21:04