我有以下几点:
<telerik:RadButton Name="AddButton" DockPanel.Dock="Right"
Content="Add" HorizontalAlignment="Right"
Click="AddButton_OnClick" Padding="5,0,5,0">
<telerik:RadButton.ContextMenu>
<ContextMenu x:Name="addContextMenu"
ItemsSource="{Binding Path=AvailableTypesToAdd}">
<ContextMenu.ItemTemplate>
<DataTemplate>
<MenuItem Header="{Binding Path=Name}"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadExpander}}, Path=DataContext.AddCommand}"
CommandParameter="{Binding}" />
</DataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
</telerik:RadButton.ContextMenu
在后面的代码中,我有以下内容:
private void AddButton_OnClick(object sender, RoutedEventArgs e)
{
AddButton.ContextMenu.PlacementTarget = this;
AddButton.ContextMenu.IsOpen = true;
}
但是,当我 LeftClick 上下文菜单是空的,但如果我右键单击它会被填充。如果我删除 PlacementTarget = this,如果我先右键单击,那么当我左键单击时它也会被填充。
有任何想法吗 ?