簡體   English   中英

獲取上下文菜單Windows Phone的父控件

[英]Get Parent control of context menu Windows phone

按住網格時有上下文菜單

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

請找到附加項目的鏈接

我為您創建了一個示例應用程序。 請檢查我所附的問題,如果還有其他問題,請通過評論更新您的問題。

另外,如果您對提供的答案感到滿意。 請標記為已回答。

拉克什R

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM