XAML Hub Control Windows 8.1 Universal, InvokeCommandAction not working

I have a hub control on my main page and in the HubSection header, I cannot get the element that fires when I click the button, however, when I move the XAML to the DataTemplate, this event if triggered. Can you explain to me why this is the case, I need to include something in the HubSection.Header for the event to fire?

here is the code that doesn't work:

 <HubSection >
                <HubSection.Header>
                    <StackPanel >
                        <TextBlock                            
                            Text="{Binding
                                WhatToWatch.Name,
                                Mode=OneWay}" />
                        <interactivity:Interaction.Behaviors>
                            <core:EventTriggerBehavior EventName="Tapped">
                                <core:InvokeCommandAction
                                    Command="{Binding ViewMoreCommand}"
                                    CommandParameter="{Binding WhatToWatch.Name}" />
                            </core:EventTriggerBehavior>
                        </interactivity:Interaction.Behaviors>
                    </StackPanel>
                </HubSection.Header>
                <DataTemplate>
                    <controls:RowGridView
                        ItemsSource="{Binding
                            WhatToWatch.Data,
                            Mode=TwoWay}" />
                </DataTemplate>
            </HubSection>

      

And here is the code that fires the event:    

                <DataTemplate>
                    <StackPanel    > 
                        <StackPanel >
                            <interactivity:Interaction.Behaviors>
                                <core:EventTriggerBehavior EventName="Tapped">
                                    <core:InvokeCommandAction Command="{Binding ViewMoreCommand}" />
                                </core:EventTriggerBehavior>
                            </interactivity:Interaction.Behaviors>
                            <TextBlock 
                                Text="{Binding
                                    WhatToWatch.Name,
                                    Mode=OneWay}" />
                        </StackPanel>
                        <controls:RowGridView 
                            ItemsSource="{Binding
                                WhatToWatch.Data,
                                Mode=TwoWay}" />
                    </StackPanel>
                </DataTemplate>
            </HubSection>

      

Its the same code, but in the second core: InvokeCommandAction acts on the DataTemplate, is this what allows the XAML to raise the event? why is it so?

+3


source to share


1 answer


You have to provide a link to your page that owns the ViewModel.

Give your page a name like: "pageRoot" then change your behavior to



<interactivity:Interaction.Behaviors>
    <core:EventTriggerBehavior EventName="Tapped">
        <core:InvokeCommandAction Command="{Binding DataContext.ViewMoreCommand, ElementName=pageRoot}" />
    </core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>

      

+1


source







All Articles