Being new to wpf and MVVM it didn't take too long for me to stumble across the little issue of dialog result (or rather the lack of it). Fortunately the number of questions on the subject in SO at least leaves me with the sense that I'm not alone.
Having looked at a myriad of answers the one that seems most akin to the principle of MVVM (at least to my new and relatively non proficient eye) was that given by Joe White here.
So far so good until it came to the little matter of translating it to VB.
What I ended up with was this;
Imports System.windows
Public NotInheritable Class DialogCloser
Private Sub New()
End Sub
Public Shared ReadOnly DialogResultProperty As DependencyProperty = DependencyProperty.RegisterAttached("DialogResult", GetType(System.Nullable(Of Boolean)), GetType(DialogCloser), New PropertyMetadata(DialogResultChanged))
Private Shared Sub DialogResultChanged(d As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim window = TryCast(d, Window)
If window IsNot Nothing Then
window.DialogResult = TryCast(e.NewValue, System.Nullable(Of Boolean))
End If
End Sub
Public Shared Sub SetDialogResult(target As Window, value As System.Nullable(Of Boolean))
target.SetValue(DialogResultProperty, value)
End Sub
End Class
This gives me two specific errors
- Argument not specified for parameter d of private shared sub DilogResultChanged
- TryCast operand must be a reference type, but Boolean? is a value type
When I look again at the original code that Joe posted there appears to be no parameter passed for 'd' and the trycast is much the same as it has been converted to. So why is this throwing errors when converted to VB?
Thanks for any light you can shed on the matter and any suggestions you might have to rectify it.