title: Send data from a WPF Window to a C# class file
body: <p>I am attempting to make a simple GUI for a console application I wrote for importing images into a database. I have a xml file that contains the different studies that the images belong to. I am populating a ListBox with the name of these studies. I have a class file named DirectoryNavigator.cs, depending on the name picked from the ListBox, this class runs processes on files within that directory. I would like to know how I can pass the Selected Value from the ListBox to the DirectoryNavigator.cs class file.</p>
  
  <p>here is my WPF window .xaml</p>
  
  <pre><code>&lt;Window x:Class="APPIL_Importer.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:local="clr-namespace:APPIL_Importer"
          mc:Ignorable="d"
          Background="Gold"
          Title="APPIL Importer" Height="385" Width="600"&gt;
      &lt;Grid Style="{StaticResource gridBackground}"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition /&gt;
              &lt;ColumnDefinition /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition /&gt;
              &lt;RowDefinition Height="Auto" /&gt;
              &lt;RowDefinition /&gt;
              &lt;RowDefinition Height="Auto" /&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;Grid.Resources&gt;
              &lt;XmlDataProvider x:Key="StudiesDataSource" Source="/Data/StudyData.xml" XPath="Studies" /&gt;
              &lt;DataTemplate x:Key="studyName"&gt;
                  &lt;Label Content="{Binding XPath=@Name}"/&gt;
              &lt;/DataTemplate&gt;
          &lt;/Grid.Resources&gt;
  
          &lt;Label Grid.Column="1" Grid.Row="0" Style="{StaticResource homeTitle}"&gt;DICOM IMPORTER&lt;/Label&gt;
  
          &lt;Image x:Name="appil_logo" Grid.Column="0" Grid.Row="0" Grid.RowSpan="4" Source="/Images/appil_logo.png"/&gt;
  
          &lt;Border Grid.Column="1" Grid.Row="0" Style="{StaticResource studyListHeader}" Width="Auto"&gt;
              &lt;Label Style="{StaticResource studyListText}"&gt;Active Studies&lt;/Label&gt;
          &lt;/Border&gt;
          &lt;ListBox Name="activeStudiesListBox" Grid.Column="1" Grid.Row="2"
                           ItemsSource="{Binding Source={StaticResource StudiesDataSource}, XPath=Study}"
                           ItemTemplate="{StaticResource studyName}"&gt;
  
          &lt;/ListBox&gt;
  
  
  
          &lt;Button Grid.Row="3" Grid.Column="1" Style="{StaticResource buttonStyle}" Click="Go_To_Study_Importer"&gt;Select&lt;/Button&gt;
  
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>here is the xaml.cs file behind the window. I am already capturing the selected value and passing it to another Window, but I don;t know how to do that to just a plain class file</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  
  namespace APPIL_Importer
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
          }
  
          private void Go_To_Study_Importer(object sender, RoutedEventArgs e)
          {
              StudyImporter studyImporter = new StudyImporter(this.activeStudiesListBox.SelectedItem);
              studyImporter.Show();
          }
      }
  }
  </code></pre>