Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to execute command from GridViewItem Tap event (XAML)
    primarykey
    data
    text
    <p>I am trying to follow the MVVM pattern in my Windows 8.1 store app (XAML).</p> <p>I want to navigate to a new view when a GridViewItem is clicked / tapped in the UI. I wanted to do this without code behind events to promote testability (using MVVM Light).</p> <p>In order to allow my UI to bind to a view model command I have been looking at the Microsoft Behaviors SDK (XAML) added via Add References -> Windows -> Extensions.</p> <p>The following code in my view compiles but blows up when I tap the grid view item. Unfortunately it offers little help &amp; just throws an unhandled win32 exception [3476]. </p> <p>Can somebody please help shed some light on the problem?</p> <p>Namespaces used are;</p> <pre><code>xmlns:interactivity="using:Microsoft.Xaml.Interactivity" xmlns:core="using:Microsoft.Xaml.Interactions.Core" &lt;GridView x:Name="itemGridView" AutomationProperties.AutomationId="ItemGridView" AutomationProperties.Name="Grouped Items" ItemsSource="{Binding Source={StaticResource GroupedSource}}" IsSwipeEnabled="True" IsTapEnabled="True"&gt; &lt;GridView.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid Margin="0" Height="230"&gt; &lt;StackPanel Orientation="Vertical" HorizontalAlignment="Stretch"&gt; &lt;Image Source="{Binding Image}" Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center" /&gt; &lt;StackPanel VerticalAlignment="Bottom" Height="45" Margin="0,-45,0,0"&gt; &lt;StackPanel.Background&gt; &lt;SolidColorBrush Color="Black" Opacity="0.75" /&gt; &lt;/StackPanel.Background&gt; &lt;TextBlock FontSize="16" Margin="2" Text="{Binding Name}" TextWrapping="Wrap" VerticalAlignment="Bottom" /&gt; &lt;/StackPanel&gt; &lt;/StackPanel&gt; &lt;interactivity:Interaction.Behaviors&gt; &lt;core:EventTriggerBehavior EventName="Tapped"&gt; &lt;core:InvokeCommandAction Command="{Binding DataContext.SummaryCatagorySelectedCommand, ElementName=LayoutRoot}" /&gt; &lt;/core:EventTriggerBehavior&gt; &lt;/interactivity:Interaction.Behaviors&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/GridView.ItemTemplate&gt; </code></pre> <p>Edit. As requested, I've added the view model, containing specifically the command I want to fire from my behavior.</p> <pre><code>public class ViewModel : ViewModelBase { public RelayCommand&lt;string&gt; SummaryCatagorySelectedCommand { get; set; } public ViewModel() { // } } </code></pre>
    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