2012-11-19 52 views

回答

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

米兰,

你需要创建一个自定义的控制或将按钮和一个弹出的用户控制。你也可以用按钮和弹出来就地实现这个。我建议你看看Callisto的菜单控件,并从那里开始实现你的下拉菜单: Callisto controls (includes a Menu)

相关问题