Example grid using a trigger:
<Grid x:Name="LayoutRoot" DataContext="{Binding ProjectGrid, Source={StaticResource Locator}}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding LoadedCommand, Mode=OneWay}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
In my ViewModel model, I install LoadedCommand as follows:
public RelayCommand<RoutedEventArgs> LoadedCommand {get;private set;}
And in the ViewModel initializer, I have the following:
public ProjectGridViewModel()
{
LoadedCommand = new RelayCommand<RoutedEventArgs>(e =>
{
this.DoLoaded(e);
}
);
}
Then in my DoLoaded, I try to do this:
Grid _projectGrid = null;
public void DoLoaded(RoutedEventArgs e)
{
_projectGrid = e.OriginalSource as Grid;
}
You can see that I'm trying to get rid of my Loaded = "" in my Grid in my opinion and instead do RelayCommand. The problem is that the original source returns nothing. My loaded event works like this, but I need to get the Grid via RoutedEventArgs.
I tried passing to the Grid in EventCommand with CommandParameter = "{Binding ElementName = LayoutRoot}", but it just crashes VS2010 when I press F5 and start the project.
? ? Loaded, #, ViewModel Views, . ViewMode .