首页 新闻 会员 周边 捐助

wpf中的ContextMenu如何获取它的源控件

0
悬赏园豆:10 [已解决问题] 解决于 2015-04-05 13:19

如题:代码如下

 <Grid  Name="MenuDropDetail" Height="80"    VerticalAlignment="Bottom" Width="855"   >
                                                        <Grid.ContextMenu> 
                                                            <ContextMenu  > 
                                                                <MenuItem  Tag="{Binding ID}" Name="Openmenu" IsEnabled="{Binding State,Converter={StaticResource IndexSoftlistMenuConverter}}" Header="打开软件" Click="Openmenu_Click" />
                                                                <MenuItem Tag="{Binding ID}" Name="Updatemenu" IsEnabled="{Binding State,Converter={StaticResource IndexSoftlistUpdateConverter}}" Header="修复" Click="Updatemenu_Click" />
                                                                <MenuItem Tag="{Binding ID}" Name="Loadmenu"  IsEnabled="{Binding State,Converter={StaticResource IndexSoftlistMenuAnzhuangConverter}}" Header="安装软件" Click="Loadmenu_Click" />
                                                                <MenuItem  Tag="{Binding ID}" Name="Upmenu" IsEnabled="{Binding State,Converter={StaticResource IndexSoftlistMenuUpConverter}}" Header="升级软件" Click="Upmenu_Click" />
                                                            <Separator />
                                                            <MenuItem Tag="{Binding ID}" Header="查看详情"  Click="MenuItem_Click_Detail" />
                                                        </ContextMenu>
                                                    </Grid.ContextMenu>

现在有个

Updatemenu_Click事件,当我点击的时候想获取这个MenuItem的父控件Grid,百度了一大圈,一时找不到,不知道怎么去获取
wpf
赶猪上架的主页 赶猪上架 | 初学一级 | 园豆:6
提问于:2015-03-05 16:52
< >
分享
最佳答案
0

var mi = sender as MenuItem;
var cm = mi.Parent as ContextMenu;
var grid = cm.PlacementTarget as Grid;

收获园豆:10
jello chen | 大侠五级 |园豆:7336 | 2015-03-05 19:01

多谢多谢

9026 | 园豆:200 (初学一级) | 2021-05-08 11:03

正解

乖乖的小马 | 园豆:200 (初学一级) | 2021-12-04 16:10
其他回答(2)
0

没有仔细看,给你点代码

<asp:LinkButton ID="LinkButtonClick" runat="server" CommandArgument='<%#Eval("ChuFaXH") %>'
OnClientClick="return confirm('是否删除?')" OnClick="LinkButtonDel_Click" CssClass="IsShanChu">删除</asp:LinkButton>

protected void LinkButtonDel_Click(object sender, EventArgs e)
{
string id = Convert.ToString((sender as LinkButton).CommandArgument);
BLL.Info_ChangSuoCFBLL bll = new BLL.Info_ChangSuoCFBLL();

bool del = bll.Delete(id);
if (del)
{
string type = Convert.ToString(Request["type"]);
string script = string.Format("<script type='text/javascript'>alert('删除成功');location.href='Info_ChangSuoFaAnList.aspx?type={0}';</script>", type);
this.ClientScript.RegisterStartupScript(this.GetType(), "aa", type);
}
else
{
this.ClientScript.RegisterStartupScript(this.GetType(), "aa", "<script type='text/javascript'>alert('删除失败');</script>");
}

}

_Vegetables | 园豆:586 (小虾三级) | 2015-03-06 10:12
0

 直接用Grid的Name不行么

CarsonCui | 园豆:162 (初学一级) | 2015-03-31 16:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册