如何确定文本菜单项抽头 [英] How to Determine ContextMenu Tapped Item
本文介绍了如何确定文本菜单项抽头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有保存按钮的StackPanel中,我添加了一个文本菜单
,使每个项目可以通过选择固定到开始屏幕菜单项
。我会如何确定哪个按钮已被选中点击
事件?
MainPage.xaml中
< StackPanel中的HorizontalAlignment =左方向=横向> <按钮X:NAME =Tile1HEIGHT =173WIDTH =173保证金=12,0,0,0点击=1_Click风格={StaticResource的ButtonStyle1}工具箱:TiltEffect.IsTiltEnabled = 真>
< Button.Content>
<图像源=/资产/瓷砖/ 1.png/>
< /Button.Content>
< /按钮>
<按钮X:NAME =Tile2HEIGHT =173WIDTH =173保证金=12,0,0,0点击=2_Click风格={StaticResource的ButtonStyle1}工具箱:TiltEffect.IsTiltEnabled = 真>
< Button.Content>
<图像源=/资产/瓷砖/ 2.png/>
< /Button.Content>
< /按钮>
<按钮X:NAME =Tile3HEIGHT =173WIDTH =173保证金=12,0,0,0点击=3_Click风格={StaticResource的ButtonStyle1}工具箱:TiltEffect.IsTiltEnabled = 真>
< Button.Content>
<图像源=/资产/瓷砖/ 3.png/>
< /Button.Content>
< /按钮>
< / StackPanel的>
<工具箱:ContextMenuService.ContextMenu>
<工具箱:文本菜单X:NAME =文本菜单>
<工具箱:菜单项标题=脚开始点击=ContextMenuItem_Tap/>
< /工具:文本菜单>
< /工具包:ContextMenuService.ContextMenu>
编辑**
将文本菜单分别为每个按钮。
< StackPanel中的HorizontalAlignment =左方向=横向> <按钮X:NAME =Tile1HEIGHT =173WIDTH =173保证金=12,0,0,0点击=1_Click风格={StaticResource的ButtonStyle1}工具箱:TiltEffect.IsTiltEnabled = 真>
< Button.Content>
<图像源=/资产/瓷砖/ 1.png/>
< /Button.Content>
<工具箱:ContextMenuService.ContextMenu>
<工具箱:文本菜单X:NAME =文本菜单>
<工具箱:菜单项标题=脚开始点击=ContextMenuItem_Tap/>
< /工具:文本菜单>
< /工具包:ContextMenuService.ContextMenu>
< /按钮>
<按钮X:NAME =Tile2HEIGHT =173WIDTH =173保证金=12,0,0,0点击=2_Click风格={StaticResource的ButtonStyle1}工具箱:TiltEffect.IsTiltEnabled = 真>
< Button.Content>
<图像源=/资产/瓷砖/ 2.png/>
< /Button.Content>
<工具箱:ContextMenuService.ContextMenu>
<工具箱:文本菜单X:NAME =文本菜单>
<工具箱:菜单项标题=脚开始点击=ContextMenuItem_Tap/>
< /工具:文本菜单>
< /工具包:ContextMenuService.ContextMenu>
< /按钮>
<按钮X:NAME =Tile3HEIGHT =173WIDTH =173保证金=12,0,0,0点击=3_Click风格={StaticResource的ButtonStyle1}工具箱:TiltEffect.IsTiltEnabled = 真>
< Button.Content>
<图像源=/资产/瓷砖/ 3.png/>
< /Button.Content>
<工具箱:ContextMenuService.ContextMenu>
<工具箱:文本菜单X:NAME =文本菜单>
<工具箱:菜单项标题=脚开始点击=ContextMenuItem_Tap/>
< /工具:文本菜单>
< /工具包:ContextMenuService.ContextMenu>
< /按钮>
< / StackPanel的>
解决方案
私人无效MenuItem_Click(对象发件人,RoutedEventArgs E)
{
VAR菜单项=(菜单项)发件人;
VAR ctxMenu =(文本菜单)menuItem.Parent;
VAR tileButton =(按钮)ctxMenu.Owner;
}
I have a StackPanel that holds buttons, and I have added a ContextMenu
so that each item may be pinned to the start screen by selecting that MenuItem
. How might I determine on the Tap
event which button has been selected?
MainPage.xaml
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<Button x:Name="Tile1" Height="173" Width="173" Margin="12,0,0,0" Click="1_Click" Style="{StaticResource ButtonStyle1}" toolkit:TiltEffect.IsTiltEnabled="True">
<Button.Content>
<Image Source="/Assets/Tiles/1.png"/>
</Button.Content>
</Button>
<Button x:Name="Tile2" Height="173" Width="173" Margin="12,0,0,0" Click="2_Click" Style="{StaticResource ButtonStyle1}" toolkit:TiltEffect.IsTiltEnabled="True">
<Button.Content>
<Image Source="/Assets/Tiles/2.png"/>
</Button.Content>
</Button>
<Button x:Name="Tile3" Height="173" Width="173" Margin="12,0,0,0" Click="3_Click" Style="{StaticResource ButtonStyle1}" toolkit:TiltEffect.IsTiltEnabled="True">
<Button.Content>
<Image Source="/Assets/Tiles/3.png"/>
</Button.Content>
</Button>
</StackPanel>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu x:Name="ContextMenu">
<toolkit:MenuItem Header="pin to start" Tap="ContextMenuItem_Tap"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
Edit**
Place the ContextMenu individually for each button.
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<Button x:Name="Tile1" Height="173" Width="173" Margin="12,0,0,0" Click="1_Click" Style="{StaticResource ButtonStyle1}" toolkit:TiltEffect.IsTiltEnabled="True">
<Button.Content>
<Image Source="/Assets/Tiles/1.png"/>
</Button.Content>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu x:Name="ContextMenu">
<toolkit:MenuItem Header="pin to start" Tap="ContextMenuItem_Tap"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</Button>
<Button x:Name="Tile2" Height="173" Width="173" Margin="12,0,0,0" Click="2_Click" Style="{StaticResource ButtonStyle1}" toolkit:TiltEffect.IsTiltEnabled="True">
<Button.Content>
<Image Source="/Assets/Tiles/2.png"/>
</Button.Content>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu x:Name="ContextMenu">
<toolkit:MenuItem Header="pin to start" Tap="ContextMenuItem_Tap"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</Button>
<Button x:Name="Tile3" Height="173" Width="173" Margin="12,0,0,0" Click="3_Click" Style="{StaticResource ButtonStyle1}" toolkit:TiltEffect.IsTiltEnabled="True">
<Button.Content>
<Image Source="/Assets/Tiles/3.png"/>
</Button.Content>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu x:Name="ContextMenu">
<toolkit:MenuItem Header="pin to start" Tap="ContextMenuItem_Tap"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</Button>
</StackPanel>
解决方案
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
var menuItem = (MenuItem) sender;
var ctxMenu = (ContextMenu) menuItem.Parent;
var tileButton = (Button) ctxMenu.Owner;
}
这篇关于如何确定文本菜单项抽头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文