2

我想drop down menu在用户单击 a 时显示 a button。类似的东西,comboBox但不是组合框,而是一个按钮。我该怎么做??

4

2 回答 2

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

        }
    }
于 2012-11-28T07:41:45.720 回答
1

米兰,

您需要创建一个自定义控件或结合了按钮和弹出窗口的用户控件。您也可以使用按钮和弹出窗口就地实现此功能。我建议您查看 Callisto 的菜单控件并从那里开始实施您的下拉菜单: Callisto 控件(包括菜单)

于 2012-11-20T01:54:49.933 回答