Get Parent control of context menu Windows phone

I have Context Menu when hold to grid

<Grid Tag="1" Tap="Grid_Tap" Style="{StaticResource GridMedium}">
    <Grid.Background>
        <ImageBrush Stretch="Fill" ImageSource="/Assets/Images/Page/bg_haivl.png"/>
    </Grid.Background>
    <toolkit:ContextMenuService.ContextMenu>
        <toolkit:ContextMenu>
            <toolkit:MenuItem Header="pin to start" Tap="MenuItem_Tap"/>
        </toolkit:ContextMenu>
    </toolkit:ContextMenuService.ContextMenu>
    <Image Source="/Assets/Images/Page/icon_haivl.png" HorizontalAlignment="Center" VerticalAlignment="Top" Width="94" Margin="0,14,0,0" />
    <Image Source="/Assets/Images/Page/logo_haivl.png" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="32" Margin="8,0,0,10" />
</Grid>

How can I get <Grid Tag="1" Tap="Grid_Tap" Style="{StaticResource GridMedium}"></Grid> by code behide MenuItem_Tap event

private void MenuItem_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    MenuItem menuItem = (MenuItem)sender;
    //...Select Grid here
}

Upvotes: 2

Views: 654

Answers (2)

Rakesh R Nair
Rakesh R Nair

Reputation: 1785

Please find the link for attached project

I created a sample application for you. Please check the one I attached and if you still have any other issues update your issues as comments.

Also if you are satisfied with the answer provided. Please mark it as answered.

Rakesh R

Upvotes: 1

Stephan Ronald
Stephan Ronald

Reputation: 1405

<Grid x:Name ="MyGrid" Tag="1" Tap="Grid_Tap" Style="{StaticResource GridMedium}">
<Grid.Background>
    <ImageBrush Stretch="Fill" ImageSource="/Assets/Images/Page/bg_haivl.png"/>
</Grid.Background>
<toolkit:ContextMenuService.ContextMenu>
    <toolkit:ContextMenu>
        <toolkit:MenuItem Header="pin to start" Tap="MenuItem_Tap"/>
    </toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<Image Source="/Assets/Images/Page/icon_haivl.png" HorizontalAlignment="Center" VerticalAlignment="Top" Width="94" Margin="0,14,0,0" />
<Image Source="/Assets/Images/Page/logo_haivl.png" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="32" Margin="8,0,0,10" />

private void MenuItem_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    MenuItem menuItem = (MenuItem)sender;

    //MyGrid.  // Access you grid here..
}

Upvotes: 0

Related Questions