Call start up function in viewmodel
<p>I'm trying to call a function in the viewmodel on startup the MVVM way. I thought I had it correct, but the code is never hitting the function call. </p>

<p>Here's my xaml:</p>

<pre><code>&lt;Window x:Class="TestWin.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:l="clr-namespace:Timeserver"
        xmlns:viewmodel="clr-namespace:Timeserver.ViewModels"
        Title="MainWindow"
        Width="893"
        Height="Auto"
        Background="LightGray"
        ResizeMode="NoResize"
        SizeToContent="Height"&gt;
    &lt;Window.DataContext&gt;
        &lt;viewmodel:MainWindowViewModel /&gt;
    &lt;/Window.DataContext&gt;
    &lt;i:Interaction.Triggers&gt;
        &lt;i:EventTrigger EventName="Loaded"&gt;
            &lt;i:InvokeCommandAction Command="{Binding LoadData}" /&gt;
        &lt;/i:EventTrigger&gt;
    &lt;/i:Interaction.Triggers&gt;
</code></pre>

<p>Here's my viewmodel (the necessary parts):</p>

<pre><code>namespace TestWin.ViewModels
{
    class MainWindowViewModel
    {
        private StructsModel model; // my model class

        private ICommand loadDataCmd;

        private ICommand showTimeWindowCmd;

        private ICommand toggleExecuteCommand { get; set; }

        private bool canExecute = true;

        public bool CanExecute
        {            
            get
            {
                return this.canExecute;
            }

            set
            {
                if (this.canExecute == value)
                {
                    return;
                }

                this.canExecute = value;
            }
        }

        public ICommand ToggleExecuteCommand
        {
            get
            {
                return toggleExecuteCommand;
            }
            set
            {
                toggleExecuteCommand = value;
            }
        }

        public ICommand ShowTimeWindowCmd
        {
            //code here
        }

        public ICommand LoadDataCmd
        {
            get
            {
                return loadDataCmd;
            }
            set
            {
                loadDataCmd = value;
            }
        }

        public void LoadData(object parameter)
        {
            model.GetData();
        }

        public MainWindowViewModel()
        {
            this.model = new StructsModel();
            LoadDataCmd = new RelayCommand(LoadData, param =&gt; this.canExecute);
            ShowTimeWindowCmd = new RelayCommand(ShowTimeWindow, param =&gt; this.canExecute);
            toggleExecuteCommand = new RelayCommand(ChangeCanExecute);
        }

        public void ShowTimeWindow(object parameter)
        {
            //code here
        }

        public void ChangeCanExecute(object obj)
        {
            canExecute = !canExecute;
        }
    }
}
</code></pre>

<p>The function in question that is not being hit is <code>LoadData()</code>. It calls <code>GetData()</code> in my model class, which I cannot show for reasons. Not sure what else to try. I've seen other questions on SO doing the same thing I'm doing. My other function <code>ShowTimeWindow</code> is set up the exact same way and does get hit. </p>