title: Closing-EventTrigger on a WPF Window - Problems with DataContext
body: <p>I have a view, which initializes a viewmodel inside the windows resources. Further more I give my grid the DataContext.</p>
  
  <p>My question is, how I can add a command to my windows closing event keeping mvvm in memory? I tried the version of this post:
  <a href="https://stackoverflow.com/questions/3683450/handling-the-window-closing-event-with-wpf-mvvm-light-toolkit">Handling the window closing event with WPF / MVVM Light Toolkit</a>
  ... but its not working using an event-trigger, because I can't access the viewmodel from outside my grid, so I can't access my command.</p>
  
  <p>Any solution for my problem?</p>
  
  <p>Greetings</p>
  
  <p>Jannik</p>
  
  <p>Edit: Here's my xaml:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.Views.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:viewModels="clr-namespace:WpfApplication1.ViewModels"
      xmlns:converter="clr-namespace:WpfApplication1.Converter"
      Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Window.Resources&gt;
          &lt;viewModels:MainWindowViewModel x:Key="ViewModel"/&gt;
      &lt;/Window.Resources&gt;
  
      &lt;Grid DataContext="{StaticResource ViewModel}"&gt;...&lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>