Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

MediaCommands Class

Provides a standard set of media related commands.

System.Object
  System.Windows.Input.MediaCommands

Namespace:  System.Windows.Input
Assembly:  PresentationCore (in PresentationCore.dll)
public static class MediaCommands

The MediaCommands type exposes the following members.

  NameDescription
Public propertyStatic memberBoostBassGets the value that represents the Boost Base command.
Public propertyStatic memberChannelDown Gets the value that represents the Channel Down command.
Public propertyStatic memberChannelUp Gets the value that represents the Channel Up command.
Public propertyStatic memberDecreaseBass Gets the value that represents the Decrease Bass command.
Public propertyStatic memberDecreaseMicrophoneVolume Gets the value that represents the Decrease Microphone Volume command.
Public propertyStatic memberDecreaseTreble Gets the value that represents the Decrease Treble command.
Public propertyStatic memberDecreaseVolume Gets the value that represents the Decrease Volume command.
Public propertyStatic memberFastForward Gets the value that represents the Fast Forward command.
Public propertyStatic memberIncreaseBass Gets the value that represents the Increase Bass command.
Public propertyStatic memberIncreaseMicrophoneVolume Gets the value that represents the Increase Microphone Volume command.
Public propertyStatic memberIncreaseTreble Gets the value that represents the Increase Treble command.
Public propertyStatic memberIncreaseVolume Gets the value that represents the Increase Volume command.
Public propertyStatic memberMuteMicrophoneVolume Gets the value that represents the Mute Microphone Volume command.
Public propertyStatic memberMuteVolume Gets the value that represents the Mute Volume command.
Public propertyStatic memberNextTrack Gets the value that represents the Next Track command.
Public propertyStatic memberPause Gets the value that represents the Pause command.
Public propertyStatic memberPlay Gets the value that represents the Play command.
Public propertyStatic memberPreviousTrack Gets the value that represents the Previous Track command.
Public propertyStatic memberRecord Gets the value that represents the Record command.
Public propertyStatic memberRewind Gets the value that represents the Rewind command.
Public propertyStatic memberSelect Gets the value that represents the Select command.
Public propertyStatic memberStop Gets the value that represents the Stop command.
Public propertyStatic memberToggleMicrophoneOnOff Gets the value that represents the Toggle Microphone On Off command.
Public propertyStatic memberTogglePlayPause Gets the value that represents the Toggle Play Pause command.
Top

The commands in the MediaCommands class and commands in the other command library classes, such as ComponentCommands and ApplicationCommands, are intended to represent a set of common commands that application programmers encounter frequently. The commands only represent the instance of the RoutedCommand and not the implementation logic for the command. The implementation logic is bound to the command via a CommandBindings. For example, if the Play command is executed on a control (the command target), the logic which performs the Play command may not be provided by the command target, so the application writer will be responsible for writing the logic that determines how the command target will handle the command.

Many controls do provide implementation logic for many of the commands in the command library. For example, the TextBox class provides logic for the Paste command, Cut command, Copy command, Undo command, and Redo command.

For more information on commands and commanding see the Commanding Overview.

The following example shows how to hook up a RoutedCommand to a Control which has built in support for the command. For a complete sample which hooks up commands to multiple sources, see the Create a Custom RoutedCommand Sample sample.

Windows Presentation Foundation (WPF) provides a library of common commands which application programmers encounter regularly. The classes which comprise the command library are: ApplicationCommands, ComponentCommands, NavigationCommands, MediaCommands, and EditingCommands.

The static RoutedCommand objects which make up these classes do not supply command logic. The logic for the command is associated with the command with a CommandBinding. Some controls have built in CommandBindings for some commands. This mechanism allows the semantics of a command to stay the same, while the actual implementation is can change. A TextBox, for example, handles the Paste command differently than a control designed to support images, but the basic idea of what it means to paste something stays the same. The command logic cannot be supplied by the command, but rather must be supplied by the control or the application.

Many controls in WPF do have built in support for some of the commands in the command library. TextBox, for example, supports many of the application edit commands such as Paste, Copy, Cut, Redo, and Undo. The application developer does not have to do anything special to get these commands to work with these controls. If the TextBox is the command target when the command is executed, it will handle the command using the CommandBinding that is built into the control.

The following shows how to use a MenuItem as the command source for the Paste command, where a TextBox is the target of the command. All the logic that defines how the TextBox performs the paste is built into the TextBox control.

A MenuItem is created and it's Command property is set to the Paste command. The CommandTarget is not explicitly set to the TextBox object. When the CommandTarget is not set, the target for the command is the element which has keyboard focus. If the element which has keyboard focus does not support the Paste command or cannot currently execute the paste command (the clipboard is empty, for example) then the MenuItem would be grayed out.

<Window x:Class="SDKSamples.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MenuItemCommandTask"
    >
    <DockPanel>
      <Menu DockPanel.Dock="Top">
        <MenuItem Command="ApplicationCommands.Paste" Width="75" />
      </Menu>
      <TextBox BorderBrush="Black" BorderThickness="2" Margin="25"
               TextWrapping="Wrap">
        The MenuItem will not be enabled until
        this TextBox gets keyboard focus  
      </TextBox>
    </DockPanel>
</Window>
// Window1 constructor 
public Window1()
{
    InitializeComponent();

    // Instantiating UIElements.
    DockPanel mainPanel = new DockPanel();
    Menu mainMenu = new Menu();
    MenuItem pasteMenuItem = new MenuItem();
    TextBox mainTextBox = new TextBox();

    // Associating the MenuItem with the Paste command.
    pasteMenuItem.Command = ApplicationCommands.Paste;

    // Setting properties on the TextBox.
    mainTextBox.Text =
        "The MenuItem will not be enabled until this TextBox receives keyboard focus.";
    mainTextBox.Margin = new Thickness(25);
    mainTextBox.BorderBrush = Brushes.Black;
    mainTextBox.BorderThickness = new Thickness(2);
    mainTextBox.TextWrapping = TextWrapping.Wrap;

    // Attaching UIElements to the Window. 
    this.AddChild(mainPanel);
    mainMenu.Items.Add(pasteMenuItem);
    mainPanel.Children.Add(mainMenu);
    mainPanel.Children.Add(mainTextBox);

    // Defining DockPanel layout.
    DockPanel.SetDock(mainMenu, Dock.Top);
    DockPanel.SetDock(mainTextBox, Dock.Bottom);
}

More Code

How to: Hook Up a Command to a Control with No Command SupportThe following example shows how to hook up a RoutedCommand to a Control which does not have built in support for the command. For a complete sample which hooks up commands to multiple sources, see the Create a Custom RoutedCommand Sample sample.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.