4

The goal is to hide/show a window from the task tray using Hardcoded WPF NotifyTrayIcon in a MVVM solution. The problem is the CommandParameter always seems to be null, which then of course cause the code to crash. I've tried a number of different bindings including:

CommandParameter="{Binding Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}}}"

CommandParameter="{Binding ElementName=window, Mode=OneWay}"

etc but everything passes back a null, any suggestions?

Thanks

Pragmateek
  • 13,174
  • 9
  • 74
  • 108
DukeNukem
  • 45
  • 4
  • 1
    Look at the Output window to view WPF debug messages, also context menus are detached from the visual tree, refer to PlacementTarget. – aybe Aug 27 '14 at 20:43
  • 1
    Do whatever you want, because passing the window to the view model isn't MVVM. –  Aug 27 '14 at 20:48

1 Answers1

0

If you have only one Window then you could simply use Application.Current.MainWindow.

If you have more then you may search for the good one in the Application.Current.Windows collection.

Pragmateek
  • 13,174
  • 9
  • 74
  • 108
  • This didn't answer the question, but solved the problem, thanks. – DukeNukem Aug 28 '14 at 23:22
  • @DukeNukem "the simpler the better" is a rule we often forget in IT. :) – Pragmateek Aug 29 '14 at 07:43
  • This doesn't help me at all, and I suspect many others as well. As @DukeNukem says, it doesn't answer the question, and I still can;'t pass the current dialogue as a command parameter on the "Cancel" button's command parameter in that dialogue. – ProfK Jan 04 '17 at 06:24