0

I stumbled upon the problem of not being able to use a windows method as a property inside the objects initializer:

 var window = new DialogWindow { DataContext = new YesNoDialogViewModel() { DialogMessage = confirmation.Content as string, DialogTitle = confirmation.Title, } }; (window.DataContext as YesNoDialogViewModel).CloseWindowCommand = new ActionCommand(window.Close); 

I wan't to do something like this:

var window = new DialogWindow { DataContext = new YesNoDialogViewModel() { DialogMessage = confirmation.Content as string, DialogTitle = confirmation.Title, CloseWindowCommand = new ActionCommand(window.Close) } }; 

However, i can't seem to figure it out (new ActionCommand(window.Close) doesnt compile, cannot use window before its declared).

Is there any hack or workaround to just add the reference to the void anyways?

1
  • @MatteoUmili yes, I figured. Thank you for the link. It's not possible apparently. Commented Jun 30, 2016 at 10:10

1 Answer 1

2

You can't put it in object initializer because ActionCommand() uses in argument the object which is not created yet - window -> window.Close().

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.