title: Access button from View in ViewModel in C#
body: <p>I am trying to access a button from <code>View</code> in <code>ViewModel</code>, but I am missing something as I get the error:</p>
  
  <pre><code>Severity    Code    Description Project File    Line    Suppression State
  Error   CS1061  'MainWindow' does not contain a definition for 'Loadfile' and no extension method 'Loadfile' accepting a first argument of type 'MainWindow' could be found (are you missing a using directive or an assembly reference?)   Uml-Creator C:\Users\HH\Source\Repos\UMLEditor\Uml-Creator\Uml-Creator\View\MainWindow.xaml 54  Active
  </code></pre>
  
  <p>The purpose of the button is to open a <code>OpenFileDialog</code>. In my <code>ViewModel</code> I handle the click like this:</p>
  
  <pre><code>class Load
      {
  
          private void Loadfile(object sender, EventArgs e)
          {
              OpenFileDialog loadfile = new OpenFileDialog();
              if (loadfile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
              {
                  //  File.Text = File.ReadAllText(loadfile.FileName);
              }
          }
  } 
  </code></pre>
  
  <p>And the View:</p>
  
  <pre><code>public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
          }
      }
  </code></pre>
  
  <p>EDIT:</p>
  
  <pre><code>&lt;Button x:Name="openButton" ToolTip="Open project" Click="Load_Click"&gt;
                      &lt;Image  Source="pack://application:,,,/Images\Open.png" Stretch="UniformToFill" Height="17"&gt;&lt;/Image&gt;
                  &lt;/Button&gt;
  </code></pre>