![](/img/trans.png)
[英]How do I get the selected item from a ListView by opening the context actions menu? (Xamarin.Forms)
[英]How do I get the selected item from Menu attached to a button
在我的.xaml中,我有一个按钮,当我单击它时,将显示一个菜单供选择。 这是我的.xaml代码:
<Button x:Name="Btn" Content="Btn" HorizontalAlignment="Left" VerticalAlignment="Top"
Height="26" Width ="40" IsEnabled="True"
Click="Btn_Click" ContextMenuService.IsEnabled="False">
我禁用了ContextMenuService,以便右键单击按钮时无法显示菜单。
下面是我左键单击菜单后显示菜单的代码。 名称“菜单”指的是上下文菜单。
private void Btn_Click(object sender, RoutedEventArgs e)
{
ContextMenu contextMenu = this.FindName("Menu") as ContextMenu;
contextMenu.PlacementTarget = sender as Button;
contextMenu.IsOpen = true;
}
有什么解决方案可以根据我的情况从上下文菜单选择中返回值吗?
听起来好像您想在上下文菜单中更改“模式”或“属性”。 因此,我要做的就是在按钮和下拉上下文菜单中创建一个UserControl,这将彼此了解。 当您在上下文菜单中更改“模式”或类似内容时,您将在UserControl属性中对其进行更改,以便该按钮也将知道它,并且您可以填充它以备后用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.