リストと詳細ビューモデルとそれらのビューが並んでいる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
は適切に動作する and にバインドされています。Get
各ステップにブレークポイントを配置すると、プロパティafterを含めてすべてヒットしましたNotifyOfPropertyChanged
。しかし、UI は更新されません。