我想在用户点击drop down menu
时显示button
。像comboBox
这样的东西,而不是comboBox的一个按钮。我该怎么办?
答案 0 :(得分:2)
我使用PopupMenu解决了它。以下是其他参考的代码。
public static Rect GetElementRect(FrameworkElement element)
{
GeneralTransform buttonTransform = element.TransformToVisual(null);
Point point = buttonTransform.TransformPoint(new Point());
return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
var menu = new PopupMenu();
menu.Commands.Add(new UICommand("Label", (command) =>
{
//do work
}));
// We don't want to obscure content, so pass in a rectangle representing the sender of the context menu event.
// We registered command callbacks; no need to handle the menu completion event
var chosenCommand = await menu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));
if (chosenCommand == null) // The command is null if no command was invoked.
{
}
}
答案 1 :(得分:1)
米兰,
您需要创建一个自定义控件或一个组合按钮和弹出窗口的用户控件。您也可以使用按钮和弹出窗口就地实现此功能。我建议你看一下Callisto的Menu控件,然后从那里开始实现你的下拉菜单: Callisto controls (includes a Menu)