1

我在一个 wpf 应用程序中使用 caliburn micro,其中我有一个列表和详细视图模型及其并排视图。从左侧列表中选择一个项目,然后在详细信息 vm 中查看右侧的详细信息。

如果详细信息IsDirty(已更改,未保存)并且他们从列表中选择了一个新项目,我想通知用户这一事实。我的工作正常。但是,如果用户单击“否”以留在他们的脏项目上,我希望列表视图留在他们当前的项目上。这是我到目前为止所拥有的:

ListViewModel

    Private _selectedItem As Library.VEntityStatusInfo
    Public Property SelectedItem As Library.VEntityStatusInfo
        Get
            Return _selectedItem
        End Get
        Set(value As Library.VEntityStatusInfo)
            Events.Publish(New SelectionChangingEvent With {.Sender = Me,
                                                            .Identification = value.Identification,
                                                            .Callback = Sub(id As Integer)
                                                                            _selectedItem = (From m In Model Where m.Identification = id).FirstOrDefault
                                                                            NotifyOfPropertyChange(Function() SelectedItem)
                                                                        End Sub})
        End Set
    End Property

DetailViewModel

Public Sub Handle(message As SelectionChangingEvent) Implements IHandle(Of SelectionChangingEvent).Handle
    If TryCast(message.Sender, EntityList.EntityListViewModel) Is Nothing Then Return

    If Me.Model Is Nothing OrElse Me.Model.Identification <> message.Identification Then
        CanChange(message.Identification, message.Callback)
    End If
End Sub

Private Sub CanChange(identification As Integer, eventCallback As System.Action(Of Integer))
    If Me.Model IsNot Nothing AndAlso Me.Model.IsDirty Then
        Dialogs.ShowMessageBox(
            "You have unsaved data.  Are you sure you want to change employee's?  All changes will be lost.",
            "Unsaved Changes",
            MessageBoxOptions.YesNo,
            Sub(box)
                If box.WasSelected(MessageBoxOptions.Yes) Then
                    If String.IsNullOrEmpty(identification) Then
                        Me.Model = Nothing
                        Me.OnRefreshed()
                    Else
                        BeginRefresh("GetByIdentificationAsync", identification)
                    End If
                    eventCallback(identification)
                Else
                    eventCallback(Model.Identification)
                End If
            End Sub)
    Else
        eventCallback(identification)
        BeginRefresh("GetByIdentificationAsync", identification)
    End If
End Sub

SelectedItem绑定到ListBox SelectedItem并且可以正常工作。当我在每个步骤中放置断点时,它们都被命中,Get包括NotifyOfPropertyChanged. 但是 UI 无法更新。

4

0 回答 0