I'm using a DataForm. So far, I've found two ways to specify its current item: a static resource, or in the code behind.
Init in code behind:
expenseDataForm.CurrentItem = new ExpenseInfo();
To save an entry:
private void expenseDataForm_EditEnded(object sender, DataFormEditEndedEventArgs e)
{
if (e.EditAction.Equals(DataFormEditAction.Commit))
{
// cast `sender` instead of hardcoding it to expenseDataForm?
expenses.Add(expenseDataForm.CurrentItem as ExpenseInfo);
expenseDataForm.CurrentItem = new ExpenseInfo();
}
}
Using resources instead:
<local:ExpenseInfo x:Key="newExpense"/>
<!-- ... -->
<df:DataForm CurrentItem="{StaticResource newExpense}" ... />
Then, when I go to save, I get problems:
private void expenseDataForm_EditEnded(object sender, DataFormEditEndedEventArgs e)
{
if (e.EditAction.Equals(DataFormEditAction.Commit))
{
// cast `sender` instead of hardcoding it to expenseDataForm?
expenses.Add(expenseDataForm.CurrentItem as ExpenseInfo);
LayoutRoot.Resources["newExpense"] = new ExpenseInfo(); // crashes here
}
}
Is this stylistically wrong? I've read that static resources are supposed to be alive through the application, although these expense info objects clearly wouldn't be. Should I just go with the code-behind route?