获取上下文菜单Windows Phone的Parent控件

时间:2013-09-11 07:14:34

标签: c# windows-phone-8

按住网格时我有上下文菜单

<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>

如何通过代码隐藏MenuItem_Tap事件

来获取<Grid Tag="1" Tap="Grid_Tap" Style="{StaticResource GridMedium}"></Grid>
private void MenuItem_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    MenuItem menuItem = (MenuItem)sender;
    //...Select Grid here
}

2 个答案:

答案 0 :(得分:1)

Please find the link for attached project

我为您创建了一个示例应用程序。请检查我附上的那个,如果您还有任何其他问题,请将您的问题更新为评论。

此外,如果您对提供的答案感到满意。请将其标记为已回答。

Rakesh R

答案 1 :(得分:0)

<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..
}