我想在用户左键单击按钮时弹出上下文菜单,我希望菜单显示在按钮上方。当用户右键单击按钮时,它应该执行相同的操作。这是我用来尝试这样做的XAML:
<Button Grid.Column="0" Width="32" Height="32" ContextMenuService.Placement="Top">
<Image Source="/Images/config.png" Width="18" Height="18" Stretch="Fill" />
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<EventTrigger RoutedEvent="Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="ContextMenu.IsOpen">
<DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="Play Sounds" IsCheckable="True" IsChecked="{Binding PlaySounds, Mode=TwoWay}" />
<MenuItem Header="Always On Top" IsCheckable="True" IsChecked="{Binding OnTop, Mode=TwoWay}" />
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>
我在&#34; PlaySounds&#34;上设置了一个断点。获取/设置属性以确保这一点得到尊重......
当我点击图标时,一切正常。上下文菜单弹出按钮上方,PlaySounds&#39; get&#39;财产被称为。但是,如果我改为左键单击图标,则会弹出菜单,点击图标的位置...不应该在按钮上方,以及&#34; PlaySounds&#34;和#34; OnTop&#34;不会调用get属性...
有没有人知道如何解决这个问题,以便LEFT点击在这里做正确的事情?