Click or drag to resize

ShellContextMenu Class

Component representing a the context menu for single or multiple shell items. It can be used in place of a normal ContextMenu on any element supporting ContextMenu. ShellItem or ShellItems contains the item(s) to show the context menu for. See examples for binding options.

MenuItems that are specified beneath the ShellContxtMenu will be added as custom items to the ShellContextMenu. ShowShellContextMenuOnTop controls the order of custom vs. shellitems in the menu.

Inheritance Hierarchy

Namespace:  Jam.Shell.WPF.Controls
Assembly:  ShellBrowserWPF (in ShellBrowserWPF.dll) Version: 1.2
Syntax
public class ShellContextMenu : ContextMenu

The ShellContextMenu type exposes the following members.

Constructors
  NameDescription
Public methodShellContextMenu
Default constructor.
Top
Properties
  NameDescription
Public propertyShellItem
Gets or sets the ItemIdList for which the context menu is invoked.
Public propertyShellItems
Gets or sets a collection of ItemIdLists defining the objects the shell context menu will be displayed for.
Public propertyShowShellContextMenuOnTop
Determines the order of shell menu items and custom menu items.
Public propertyVersion
The current version of ShellBrowser Components WPF.
Top
Methods
  NameDescription
Protected methodOnOpened
Called when the Opened event occurs. Opens the ShellContextMenu instead.
(Overrides ContextMenuOnOpened(RoutedEventArgs).)
Protected methodOnPropertyChanged
Invoked whenever the effective value of any dependency property on this FrameworkElement has been updated. The specific dependency property that changed is reported in the arguments parameter. Overrides OnPropertyChanged(DependencyPropertyChangedEventArgs) .
(Overrides FrameworkElementOnPropertyChanged(DependencyPropertyChangedEventArgs).)
Protected methodOnRenameItemSelected
Fires the RenameItemSelected event
Top
Events
  NameDescription
Public eventRenameItemSelected
This event is fired when the context menu option "Rename" is selected from the context menu or passed to ExecuteCommand(ShellContextMenuCommand).
Top
Fields
  NameDescription
Public fieldStatic memberShellItemProperty
The DependencyProperty for Location.
Public fieldStatic memberShellItemsProperty
Using a DependencyProperty as the backing store for Selection. This enables animation, styling, binding, etc...
Top
Examples
The following examples show how to realise the bindings on single path or a JamShellItemCollection.
XAML
<TextBox Name="PathEdit" Text="{Binding SelectedFile, Mode=TwoWay}">
    <TextBox.ContextMenu>
        <!-- Shows the shell context menu for file path contained in the parent TextBox -->
        <shlbr:ShellContextMenu ShellItem="{Binding PlacementTarget.Text, RelativeSource={RelativeSource Self}}"/>
    </TextBox.ContextMenu>
</TextBox>
XAML
<ListView Name="listView1" ItemsSource="{Binding CurrentDirectory}">
    <ListView.Resources>
        <DataTemplate DataType="{x:Type shellbrowser:ItemIdList}">
            <StackPanel Orientation="Horizontal">
                <shlbr:ShellThumbnail ImageSize="SmallIcons" Location="{Binding}"/>
                <TextBlock Padding="10, 0, 0, 0" Text="{Binding Path=Caption}"/>
            </StackPanel>
        </DataTemplate>
    </ListView.Resources>
    <ListView.ContextMenu>
        <!-- Shows the shell context menu for the ItemIdLists contained in SelectedItemIdLists - a JamShellItemCollection held in the viewmodel and updated to represent the ListView's SelectedItems property. -->
        <shlbr:ShellContextMenu ShellItems="{Binding SelectedItemIdLists}"/>
    </ListView.ContextMenu>
</ListView>
The following example illustrates how to add custom items to a ShellContextMenu.
XAML
<ListView Name="listView3" ItemsSource="{Binding CurrentDirectory}">
    <ListView.Resources>
        <DataTemplate DataType="{x:Type shellbrowser:ItemIdList}">
            <StackPanel Orientation="Horizontal">
                <shlbr:ShellThumbnail ImageSize="SmallIcons" Location="{Binding}"/>
                <TextBlock Padding="10, 0, 0, 0" Text="{Binding Path=Caption}"/>
            </StackPanel>
        </DataTemplate>
    </ListView.Resources>
    <ListView.ContextMenu>
        <!-- Shows the shell context menu for the ItemIdLists available through the SelectedItems property of the ListView. -->
        <shlbr:ShellContextMenu ShellItems="{Binding ElementName=listView2, Path=SelectedItems}">
            <!-- 2 custom menu items are added to the top, on is handled via click eventhandler, the other via Command.:-->
            <MenuItem Header="Open cmd here" 
                      Command="{Binding OpenCmdPrompt}" 
                      CommandParameter="{Binding PlacementTarget.SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
            />
            <MenuItem Header="Sum file sizes" Click="MenuItem_Click"/>
        </shlbr:ShellContextMenu>
    </ListView.ContextMenu>
</ListView>
See Also