我有一个客户端实体的列表和详细信息应用,当用户点击addnewandedit
按钮时,我想打开一个有限数量字段的自定义模式屏幕。
在指南中,它说创建一个新的“详细信息”屏幕并将其设置为默认值应该这样做,但它不使用自定义屏幕并仍然使用自动生成的屏幕。
我尝试用application.showcustomAddClient()
覆盖按钮,但这会将其作为标签打开,而不是像自动生成的模式窗口那样。
然后我尝试将customaddclient
设置为模态窗口但现在当我点击addandeditnew
时,我得到一个我必须单击的按钮,然后打开屏幕作为模态窗口,我可以弄清楚为什么它不会直接打开模态窗口?
我尝试调用application.showscreen(customaddclient,Enumerable.Empty<object>())
,但语法错误。
有关如何指定用于自定义addandeditnew
的模式屏幕的任何帮助都会非常有用。
答案 0 :(得分:1)
对于我的自定义模态Windows,我喜欢使用@YannDuran的Modal Windows Helper Class。在创建它时,将传递给要添加的表或查询,自定义模态窗口的名称,以及可选地放置在模态窗口顶部的标题。该课程非常重视其余部分,包括正确处理X
按钮。
您的代码将是这样的:
'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