I'm trying to show a dialog window when something throws an error in my application. When the viewmodel wants to launch a dialog, it fires an event and the View's code behind answers by creating a new Dialog window and showing it. The problem that I have is that I cannot pass any info to the dialog (like the error message), because the DialogViewModel isn't loaded when I create the DialogView.
I tried this on the DialogView constructor:
public DialogView() {
InitializeComponent();
var vm = (DialogViewModel)DataContext;
if( vm != null ) {
vm.ErrorInfo= "Sample error message";
}
}
but this doesn't work because the DialogViewModel is null.
DataContextof the dialog (orContentproperty, depending on how you handle the layout of the dialog).MainWindow.xaml.cs