Get ViewModel data after ShowDialog

Topics: Questions
Sep 17, 2014 at 9:40 PM
This is similar to:

Using Catel 3.9. I have a simple View/ViewModel where the Customer can input a year. I display this using IUIVisualizerService.ShowDialog. When the Customer enters a valid year and clicks OK, I then try to get the entered year from the ViewModel, but the value is always null. I suspect when the view is closed, the ViewModel is also closed.
var vm = new NewProgramCountYearViewModel();
if (this._uiVisualizerService.ShowDialog(vm) ?? false)
    int? year = vm.Year;
    MessageBox.Show("You clicked OK and entered: " + 
Is there an easy way to retrieve the value the Customer entered?
Sep 19, 2014 at 1:44 PM
It should work. Although a VM is closed, it doesn't mean the values are reset to default values. I use this code in multiple applications. Are you sure you are not resetting the Year property yourself somehow?
Sep 19, 2014 at 8:23 PM
Edited Sep 19, 2014 at 9:59 PM
I agree -- it should work as I've seen where it is used in one of your examples.

In my production code, I added a parameter (a list of years we wanted to exclude) to the view model's and model's constructors so the model could do some validation.
var vm = new NewProgramCountYearViewModel(this.excludeTheseYears);
After that, the code suddenly started working. If I comment out the constructor parameters, the returned Year value is again null.

I'm trying to workup a simple repro for you, but right now I can't get it to fail. If I come up with something, I'll let you know.


Update: I was able to create a simple repro that shows classes that work and classes that don't work. The only difference (besides the names of course) is I pass an integer as a parameter to the view model -> model constructors in the classes that work. Please let me know where to send this.
Sep 20, 2014 at 9:09 PM
Sep 22, 2014 at 4:53 PM
Created new issue. Thanks.