开发者

Silverlight 4 dataform add new item

I'm using a Silverlight 4 dataform and attempting to use the inbuilt add button to create a new item in my collection. It works fine except that I have a number of properties that need to be set behind the scenes. I've tried hooking into the likely looking events such as AddingNewItem but the new item is readonly at that 开发者_Python百科point and I can't set the properties.

Is there a trick to add new items using the Silverlight 4 dataform?


Finally stumbled on the way to do it after much searching and trial and error.

The rather counter-intuitive place to set the properties on a newly created dataform item is in the EditEnding event handler. The dataform Mode property is readonly in the AddingNewItem handler but is equal to AddNew in the EditEnding handler.

My EditEnding handler code is along the lines of:

private void EditEnding(object sender, DataFormEditEndingEventArgs e)
{
     if (myDataForm.Mode == DataFormMode.AddNew)
     {
          MyItem item = myDataForm.CurrentItem as MyItem;
          item.ID = Guid.NewGuid().ToString();
     }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜