Reputation: 23831
I have the following ListBox
. This works great and when I left click on the TextBlock
it opens the recent file. However, when I right click the context menu does not open, instead it acts like a left click and the command LoadSelectedFileCommand
fires, opening the recent document. Below is the ListBox
XAML:
<ListBox ItemsSource="{Binding RecentFiles, NotifyOnSourceUpdated=True, IsAsync=True, Mode=TwoWay}"
ItemContainerStyle="{StaticResource MenuListBoxItem}"
VerticalAlignment="Stretch"
Grid.Row="6" >
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type RecentObjects:RecentFile}">
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsPinned}"
Style="{StaticResource imageCheckBox}"
ToolTip="{Binding IsPinned, Converter={StaticResource BooleanToVariableStringConverter}}"
DataAccess:DocumentCheckBox.IsCheckedOnData="{DynamicResource Pinned}"
DataAccess:DocumentCheckBox.IsCheckedOffData="{DynamicResource UnPinned}"
AttachedCommand:CommandBehavior.Event="Click"
AttachedCommand:CommandBehavior.Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MahAppsControls:MetroContentControl}}, Path=DataContext.UpdateRecentFilesCommand}" >
</CheckBox>
<TextBlock Text="{Binding FileName}"
Style="{StaticResource MenuTextBlock}"
ToolTip="{Binding FullFileName}"
AttachedCommand:CommandBehavior.Event="MouseDown"
AttachedCommand:CommandBehavior.Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MahAppsControls:MetroContentControl}}, Path=DataContext.LoadSelectedFileCommand}"
AttachedCommand:CommandBehavior.CommandParameter="{Binding FullFileName}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Open Study" />
<MenuItem Header="Open Containing Folder" />
<MenuItem Header="Remove From List" />
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
My question is how can I get the context menu to fire on the right click and the command to open on the left click?
Thanks for your time.
Upvotes: 1
Views: 408
Reputation: 2179
If you only want the LoadSelectedFileCommand to run when the left mouse button is clicked you should use the UIElement.MouseLeftButtonDown Event instead.
Upvotes: 1