我正在使用Controls:Tiles
开发一个菜单栏,其属性为ContextMenu
,只允许我点击鼠标右键打开它。经过一些搜索后,我用鼠标左键点击它,但行为不同:当我按下右键单击ContextMenu
时,所有MenuItems
都可以点击。当我按左键单击ContextMenu
打开但所有MenuItems
看起来已禁用,我无法点击它们。
我的代码在这里:
<Controls:Tile x:Name="FileTile" Width="Auto" Height="30" TitleFontSize="10" HorizontalContentAlignment="Left"
VerticalAlignment="Top" VerticalContentAlignment="Top" Background="White" HorizontalTitleAlignment="Right"
Foreground="Gray" ContextMenuService.IsEnabled="True">
<Controls:Tile.Content>
<StackPanel Orientation="Horizontal" Height="Auto">
<Image Source="/images/topbaricons/files.png" Width="22" Height="22" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock Text="{x:Static p:Resources.File}" VerticalAlignment="Center" Margin="5,0,5,0" />
</StackPanel>
</Controls:Tile.Content>
<Controls:Tile.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<EventTrigger RoutedEvent="Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="ContextMenu.IsOpen" FillBehavior="HoldEnd">
<DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>
</Controls:Tile.Style>
<Controls:Tile.ContextMenu>
<ContextMenu x:Name="File_ContextMenu" >
<MenuItem Header="{x:Static p:Resources.Menu_item_New}" Command="ApplicationCommands.New" IsEnabled="true">
<MenuItem.Icon>
<Image Source="/images/topbaricons/new_file.png" Height="22" Width="22" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{x:Static p:Resources.Menu_item_Open}" Command="ApplicationCommands.Open" IsEnabled="true">
<MenuItem.Icon>
<Image Source="/images/topbaricons/open_file.png" Height="22" Width="22" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{x:Static p:Resources.Menu_item_Save}" x:Name="MenuItemSave" Command="ApplicationCommands.Save" IsEnabled="False">
<MenuItem.Icon>
<Image Source="/images/topbaricons/save.png" Height="22" Width="22" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="ApplicationCommands.SaveAs" Visibility="Visible" >
<MenuItem.Icon>
<Image Source="/images/topbaricons/save_as.png" Height="22" Width="22" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{x:Static p:Resources.Menu_item_Exit}" Command="ApplicationCommands.Close" IsEnabled="true">
<MenuItem.Icon>
<Image Source="/images/topbaricons/off.png" Height="22" Width="22" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Controls:Tile.ContextMenu>
</Controls:Tile>
为了准确显示我在这篇文章中所讨论的差异,有这个图像:
有人能帮助我吗?我真的想左键单击我可以做的右键单击。
感谢。
答案 0 :(得分:0)
我认为命令的Pid
将在某处处理(也许当前关注的元素具有自己的实现)。粘贴
link/1
和
CanExecute
应该这样做。