Pergunta

I followed this tutorial by Microsoft and it worked fantastically, until I upgraded to Beta 2.

http://msdn.microsoft.com/en-us/lightswitch/Video/ff945359

The thing this is when using a so called 'Data Item' which isn't filled with data it will create an exception.

So the question is: has anyone which uses a new screen also uses it for editing and had this problem and how did you fix this?

Possible scenario's:

  • Start a new Beta 2 project and create separate new and edit screens (means double work)
  • Find a fix somehow by binding the (not used in new mode) data item with an existing record (would be a ugly fix)
  • Find another way to create a new / edit screen.
  • Option 4?
Foi útil?

Solução 2

I use the following logic to open the same screen for both editing or adding a record:

partial void CreateNewOrEditJob_InitializeDataWorkspace(List<IDataService> saveChangesTo)
        {
            Job selectedJob;

            if (SelectedJobId.HasValue)
            {
                int selectedId = (int)SelectedJobId;
                selectedJob = DataWorkspace.ApplicationData.Jobs.Where(j => j.Id.Equals(selectedId)).FirstOrDefault();
            }
            else
            {
                selectedJob = new Job();
            }
            this.JobProperty = selectedJob;
    }

The above example is used for a screen that is used to either edit an existing "Job" entity, or create a new one. The "SelectedJobId" is a Local Property for the screen, with the Is Parameter set to true, and the Is Required set to false.


Credits go to Paul Patterson Quercus Solutions Inc (MVP)

Outras dicas

I use a modified version of Beth's original code (first in B2, then RTM, & I'm pretty sure it works in V2 Beta), because there's a bug that used to sometimes occur (but I don't remember under what condition any more, as I've been using my code for quite a while now).

The very first code that Beth made available used an "Edit Data" screen (but maybe that was B1?), then she later released an updated version that uses the "Add New Data" screen (the video you pointed to was for B2).

If you still haven't managed to get it to work, I can point you at the code that I use.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top