开发者

MVVM & DataForm - How to set values for non-displayed fields

I'm using SL4 and RIA services. I have a simple table with 3 fields (Name, UpDatedByUserId, UpDatedOn). In my metadata I use Data Annotation on the 2 latter fields so that they do not display. My DataGrid and the related DataForm show each record correctly and, as required, the DataForm only shows the Name field but of course I want to programmatically set values for the other 2开发者_开发知识库 fields (UpDatedByUserId and UpDatedOn). Is there a way I can set those values in the ViewModel?


In your ViewModel you could setup your Name property like so:

private string _UpdatedByUserId;
private DateTime _UpdatedOn;
private string _Name;
public string Name 
{
   get { return _Name; }
   set
   {
      if(value != _Name)
      {
         _UpdatedByUserId = WebContext.Current.User.Name;
         _UpdatedOn = DateTime.Now;
         _Name = value;
      }
   }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜