Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you send in the LayoutRoot into a RelayCommand via a EventToCommand?
    primarykey
    data
    text
    <p><strong>Grid example with the trigger:</strong></p> <pre><code>&lt;Grid x:Name="LayoutRoot" DataContext="{Binding ProjectGrid, Source={StaticResource Locator}}"&gt; &lt;i:Interaction.Triggers&gt; &lt;i:EventTrigger EventName="Loaded"&gt; &lt;GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding LoadedCommand, Mode=OneWay}" PassEventArgsToCommand="True"/&gt; &lt;/i:EventTrigger&gt; &lt;/i:Interaction.Triggers&gt; </code></pre> <p><strong>In my ViewModel I set the LoadedCommand like this:</strong></p> <pre><code>public RelayCommand&lt;RoutedEventArgs&gt; LoadedCommand {get;private set;} </code></pre> <p><strong>And in the ViewModel initializer I have this:</strong></p> <pre><code>public ProjectGridViewModel() { LoadedCommand = new RelayCommand&lt;RoutedEventArgs&gt;(e =&gt; { this.DoLoaded(e); } ); } </code></pre> <p><strong>Then, in my DoLoaded I'm trying to do this:</strong></p> <pre><code>Grid _projectGrid = null; public void DoLoaded(RoutedEventArgs e) { _projectGrid = e.OriginalSource as Grid; } </code></pre> <p>You can see I'm trying to get rid of my Loaded="" in my Grid in my view, and do a RelayCommand instead. <strong>The issue is the OriginalSource brings back nothing.</strong> My loaded event is running nice this way, but I need to get the Grid in via the RoutedEventArgs it seems.</p> <p>I tried passing in the Grid in the EventCommand with CommandParameter="{Binding ElementName=LayoutRoot}", but this just crashes VS2010 when hitting F5 and running the project.</p> <p>Any ideas? Or a better way to do this? I had the Loaded event run in the views C# then call the ViewModel in the Views code-behind, but I'd like to do a nicer binding. Talking to the ViewMode in the Views code-behind feels like a hack.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload