Pergunta

I have a List and details app for the clients entity, when the user clicks the addnewandedit button I want to open a custom modal screen with a limited number of fields.

In the guide it says that creating a new 'details' screen and setting this as default should do this, but it doesn't use the custom screen and still uses the auto generated one.

I tried overriding the button with application.showcustomAddClient() but this opens it as a tab, not as a modal window like the auto generated one does.

I then tried setting the customaddclient as a modal window but now when I click on addandeditnew I get a button which I have to click, which then opens the screen as a modal window, I can't work out why it won't open the modal window directly?

I tried calling the application.showscreen(customaddclient,Enumerable.Empty<object>()) but get an error in the syntax.

Any help on how to specify which modal screen to use for a custom addandeditnew would be very helpful.

Foi útil?

Solução

For my custom Modal Windows, I like to use the Modal Windows Helper Class by @YannDuran. When you create it, you pass it the table or query you want to add to, the name of your custom Modal Window, and, optionally, a title to place at the top of your Modal Window. The class pretty much takes care of the rest including proper handleing of the X button.

Your code would then be something like this:

'Declare a Modal Window Helper for use in this screen
Private AddClientHelper As ModalWindowHelper

Private Sub ScreenName_InitializeDataWorkspace(saveChangesTo As System.Collections.Generic.List(Of Microsoft.LightSwitch.IDataService))
    'Create Helpers
    Me.AddClientHelper = New ModalWindowHelper(Me.qClientTable, "mwAddClient", "Add Client")
End Sub

Private Sub ScreenName_Created()
    'Initialize Helpers
    Me.AddClientHelper.Initialise()
End Sub

Private Sub qClientTableAddAndEditNew_CanExecute(ByRef result As Boolean)
    'Check to see if user is allowed to add an Entity
    result = Me.AddClientHelper.CanAdd()
End Sub

Private Sub qClientTableAddAndEditNew_Execute()
    'Add a new Entity to the Collection
    Me.AddClientHelper.AddEntity()
End Sub

Private Sub qClientTableEditSelected_CanExecute(ByRef result As Boolean)
    'Check to see if user is allowed to view an Entity
    result = Me.AddClientHelper.CanView()
End Sub

Private Sub qClientTableEditSelected_Execute()
    'Open selected Entity for viewing/editing
    Me.AddClientHelper.ViewEntity()
End Sub

'Save button on custom Modal Window
Private Sub btnSaveClient_Execute()
    'Check for validation errors
    If (Me.Details.ValidationResults.HasErrors = False) Then
        'Close the modal window
        Me.AddClientHelper.DialogOk()

        'Save the new Client to the database
        Me.Save()
    Else
        'If validation errors exist,
        Dim res As String = ""
        'Add each one to a string,
        For Each msg In Me.Details.ValidationResults
            res = res & msg.Property.DisplayName & ": " & msg.Message & vbCrLf
        Next msg

        'And display them in a message box
        Me.ShowMessageBox(res, "Validation error", MessageBoxOption.Ok)
    End If
End Sub

'Cancel button on custom Modal Window
Private Sub btnCancelClient_Execute()
    'Cancel the entry, discarding the changes
    Me.AddClientHelper.DialogCancel()
End Sub
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top