CommandBar Class

Represents a specialized app bar that provides layout for AppBarButton and related command elements.

继承

Object
  DependencyObject
    UIElement
      FrameworkElement
        Control
          ContentControl
            AppBar
              CommandBar

语法


public ref class CommandBar : AppBar


<CommandBar .../>
-or-
<CommandBar>
  commandBarElements
</CommandBar>

XAML Values

commandBarElements

One or more object elements for classes that implement ICommandBarElement.这些通常是 AppBarButtonAppBarToggleButtonAppBarSeparator 元素。

特性

[ContentProperty("Name=PrimaryCommands")]
[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06030000)]
[WebHostHidden()]

成员

CommandBar类 具有这些类型的成员:

构造函数

CommandBar类 具有这些构造函数。

构造函数说明
CommandBar Initializes a new instance of the CommandBar class.

 

事件

CommandBar类 具有这些事件。

事件说明
Closed Occurs when the AppBar changes from visible to hidden. (继承自AppBar)
DataContextChanged Occurs when the value of the FrameworkElement.DataContext property changes. (继承自FrameworkElement)
DoubleTapped Occurs when an otherwise unhandled DoubleTap interaction occurs over the hit test area of this element. (继承自UIElement)
DragEnter Occurs when the input system reports an underlying drag event with this element as the target. (继承自UIElement)
DragLeave Occurs when the input system reports an underlying drag event with this element as the origin. (继承自UIElement)
DragOver Occurs when the input system reports an underlying drag event with this element as the potential drop target. (继承自UIElement)
Drop Occurs when the input system reports an underlying drop event with this element as the drop target. (继承自UIElement)
GotFocus Occurs when a UIElement receives focus. (继承自UIElement)
Holding Occurs when an otherwise unhandled Hold interaction occurs over the hit test area of this element. (继承自UIElement)
IsEnabledChanged Occurs when the IsEnabled property changes. (继承自Control)
KeyDown Occurs when a keyboard key is pressed while the UIElement has focus. (继承自UIElement)
KeyUp Occurs when a keyboard key is released while the UIElement has focus. (继承自UIElement)
LayoutUpdated Occurs when the layout of the visual tree changes, due to layout-relevant properties changing value or some other action that refreshes the layout. (继承自FrameworkElement)
Loaded Occurs when a FrameworkElement has been constructed and added to the object tree, and is ready for interaction. (继承自FrameworkElement)
LostFocus Occurs when a UIElement loses focus. (继承自UIElement)
ManipulationCompleted Occurs when a manipulation on the UIElement is complete. (继承自UIElement)
ManipulationDelta Occurs when the input device changes position during a manipulation. (继承自UIElement)
ManipulationInertiaStarting Occurs when the input device loses contact with the UIElement object during a manipulation and inertia begins. (继承自UIElement)
ManipulationStarted Occurs when an input device begins a manipulation on the UIElement. (继承自UIElement)
ManipulationStarting Occurs when the manipulation processor is first created. (继承自UIElement)
Opened Occurs when the AppBar changes from hidden to visible. (继承自AppBar)
PointerCanceled Occurs when a pointer that made contact abnormally loses contact. (继承自UIElement)
PointerCaptureLost Occurs when pointer capture previously held by this element moves to another element or elsewhere. (继承自UIElement)
PointerEntered Occurs when a pointer enters the hit test area of this element. (继承自UIElement)
PointerExited Occurs when a pointer leaves the hit test area of this element. (继承自UIElement)
PointerMoved Occurs when a pointer moves while the pointer remains within the hit test area of this element. (继承自UIElement)
PointerPressed Occurs when the pointer device initiates a Press action within this element. (继承自UIElement)
PointerReleased Occurs when the pointer device that previously initiated a Press action is released, while within this element. (继承自UIElement)
PointerWheelChanged Occurs when the delta value of a pointer wheel changes. (继承自UIElement)
RightTapped Occurs when a right-tap input stimulus happens while the pointer is over the element. (继承自UIElement)
SizeChanged Occurs when either the ActualHeight or the ActualWidth property changes value on a FrameworkElement. (继承自FrameworkElement)
Tapped Occurs when an otherwise unhandled Tap interaction occurs over the hit test area of this element. (继承自UIElement)
Unloaded Occurs when this object is no longer connected to the main object tree. (继承自FrameworkElement)

 

方法

The CommandBar 类 具有这些方法。 它还继承方法于Object 类.

方法说明
AddHandler Adds a routed event handler for a specified routed event, adding the handler to the handler collection on the current element. Specify handledEventsToo as true to have the provided handler be invoked even if the event is handled elsewhere. (继承自UIElement)
ApplyTemplate Loads the relevant control template so that its parts can be referenced. (继承自Control)
Arrange Positions child objects and determines a size for a UIElement. Parent objects that implement custom layout for their child elements should call this method from their layout override implementations to form a recursive layout update. (继承自UIElement)
ArrangeOverride Provides the behavior for the Arrange pass of layout. Classes can override this method to define their own Arrange pass behavior. (继承自FrameworkElement)
CancelDirectManipulations Cancels ongoing direct manipulation processing (system-defined panning/zooming) on any ScrollViewer parent that contains the current UIElement. (继承自UIElement)
CapturePointer Sets pointer capture to a UIElement. Once captured, only the element that has capture will fire pointer-related events. (继承自UIElement)
ClearValue Clears the local value of a dependency property. (继承自DependencyObject)
FindName Retrieves an object that has the specified identifier name. (继承自FrameworkElement)
FindSubElementsForTouchTargeting Enables a UIElement subclass to expose child elements that assist with resolving touch targeting. (继承自UIElement)
Focus Attempts to set the focus on the control. (继承自Control)
GetAnimationBaseValue Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (继承自DependencyObject)
GetBindingExpression Returns the BindingExpression that represents the binding on the specified property. (继承自FrameworkElement)
GetTemplateChild Retrieves the named element in the instantiated ControlTemplate visual tree. (继承自Control)
GetValue Returns the current effective value of a dependency property from a DependencyObject. (继承自DependencyObject)
GoToElementStateCore When implemented in a derived class, enables per-state construction of a visual tree for a control template in code, rather than by loading XAML for all states at control startup. (继承自FrameworkElement)
InvalidateArrange Invalidates the arrange state (layout) for a UIElement. After the invalidation, the UIElement will have its layout updated, which will occur asynchronously. (继承自UIElement)
InvalidateMeasure Invalidates the measurement state (layout) for a UIElement. (继承自UIElement)
Measure Updates the DesiredSize of a UIElement. Typically, objects that implement custom layout for their layout children call this method from their own MeasureOverride implementations to form a recursive layout update. (继承自UIElement)
MeasureOverride Provides the behavior for the Measure pass of the layout cycle. Classes can override this method to define their own Measure pass behavior. (继承自FrameworkElement)
OnApplyTemplate Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in your app. Override this method to influence the default post-template logic of a class. (继承自FrameworkElement)
OnClosed Invoked when the AppBar changes from visible to hidden. (继承自AppBar)
OnContentChanged Invoked when the value of the Content property changes. (继承自ContentControl)
OnContentTemplateChanged Invoked when the value of the ContentTemplate property changes. (继承自ContentControl)
OnContentTemplateSelectorChanged Invoked when the value of the ContentTemplateSelector property changes. (继承自ContentControl)
OnCreateAutomationPeer When implemented in a derived class, returns class-specific AutomationPeer implementations for the Microsoft UI Automation infrastructure. (继承自UIElement)
OnDisconnectVisualChildren Override this method to implement how layout and logic should behave when items are removed from a class-specific content or children property. (继承自UIElement)
OnDoubleTapped Called before the DoubleTapped event occurs. (继承自Control)
OnDragEnter Called before the DragEnter event occurs. (继承自Control)
OnDragLeave Called before the DragLeave event occurs. (继承自Control)
OnDragOver Called before the DragOver event occurs. (继承自Control)
OnDrop Called before the Drop event occurs. (继承自Control)
OnGotFocus Called before the GotFocus event occurs. (继承自Control)
OnHolding Called before the Holding event occurs. (继承自Control)
OnKeyDown Called before the KeyDown event occurs. (继承自Control)
OnKeyUp Called before the KeyUp event occurs. (继承自Control)
OnLostFocus Called before the LostFocus event occurs. (继承自Control)
OnManipulationCompleted Called before the ManipulationCompleted event occurs. (继承自Control)
OnManipulationDelta Called before the ManipulationDelta event occurs. (继承自Control)
OnManipulationInertiaStarting Called before the ManipulationInertiaStarting event occurs. (继承自Control)
OnManipulationStarted Called before the ManipulationStarted event occurs. (继承自Control)
OnManipulationStarting Called before the ManipulationStarting event occurs. (继承自Control)
OnOpened Invoked when the AppBar changes from hidden to visible, or is first displayed. (继承自AppBar)
OnPointerCanceled Called before the PointerCanceled event occurs. (继承自Control)
OnPointerCaptureLost Called before the PointerCaptureLost event occurs. (继承自Control)
OnPointerEntered Called before the PointerEntered event occurs. (继承自Control)
OnPointerExited Called before the PointerExited event occurs. (继承自Control)
OnPointerMoved Called before the PointerMoved event occurs. (继承自Control)
OnPointerPressed Called before the PointerPressed event occurs. (继承自Control)
OnPointerReleased Called before the PointerReleased event occurs. (继承自Control)
OnPointerWheelChanged Called before the PointerWheelChanged event occurs. (继承自Control)
OnRightTapped Called before the RightTapped event occurs. (继承自Control)
OnTapped Called before the Tapped event occurs. (继承自Control)
ReadLocalValue Returns the local value of a dependency property, if a local value is set. (继承自DependencyObject)
ReleasePointerCapture Releases pointer captures for capture of one specific pointer by this UIElement. (继承自UIElement)
ReleasePointerCaptures Releases all pointer captures held by this element. (继承自UIElement)
RemoveHandler Removes the specified routed event handler from this UIElement. Typically the handler in question was added by AddHandler. (继承自UIElement)
SetBinding Attaches a binding to a FrameworkElement, using the provided binding object. (继承自FrameworkElement)
SetValue Sets the local value of a dependency property on a DependencyObject. (继承自DependencyObject)
TransformToVisual Returns a transform object that can be used to transform coordinates from the UIElement to the specified object. (继承自UIElement)
UpdateLayout Ensures that all positions of child objects of a UIElement are properly updated for layout. (继承自UIElement)

 

属性

CommandBar类 具有这些属性。

属性访问类型说明

ActualHeight

只读Gets the rendered height of a FrameworkElement. (继承自FrameworkElement)

ActualWidth

只读Gets the rendered width of a FrameworkElement. (继承自FrameworkElement)

AllowDrop

读/写Gets or sets a value that determines whether this UIElement can be a drop target for purposes of drag-and-drop operations. (继承自UIElement)

Background

读/写Gets or sets a brush that provides the background of the control. (继承自Control)

BaseUri

只读Gets a Uniform Resource Identifier (URI) that represents the base Uniform Resource Identifier (URI) for an XAML-constructed object at XAML load time. This property is useful for Uniform Resource Identifier (URI) resolution at run time. (继承自FrameworkElement)

BorderBrush

读/写Gets or sets a brush that describes the border background of a control. (继承自Control)

BorderThickness

读/写Gets or sets the border thickness of a control. (继承自Control)

CacheMode

读/写Gets or sets a value that indicates that rendered content should be cached as a composited bitmap when possible. (继承自UIElement)

CharacterSpacing

读/写Gets or sets the uniform spacing between characters, in units of 1/1000 of an em. (继承自Control)

Clip

读/写Gets or sets the RectangleGeometry used to define the outline of the contents of a UIElement. (继承自UIElement)

CompositeMode

读/写Gets or sets a property that declares alternate composition and blending modes for the element in its parent layout and window. This is relevant for elements that are involved in a mixed XAML / Microsoft DirectX UI. (继承自UIElement)

Content

读/写Gets or sets the content of a ContentControl. (继承自ContentControl)

ContentTemplate

读/写Gets or sets the data template that is used to display the content of the ContentControl. (继承自ContentControl)

ContentTemplateRoot

只读Gets the root element of the date template specified by the ContentTemplate property. (继承自ContentControl)

ContentTemplateSelector

读/写Gets or sets a selection object that changes the DataTemplate to apply for content, based on processing information about the content item or its container at run time. (继承自ContentControl)

ContentTransitions

读/写Gets or sets the collection of Transition style elements that apply to the content of a ContentControl. (继承自ContentControl)

DataContext

读/写Gets or sets the data context for a FrameworkElement when it participates in data binding. (继承自FrameworkElement)

DefaultStyleKey

读/写Gets or sets the key that references the default style for the control. Authors of custom controls use this property to change the default for the style that their control uses. (继承自Control)

DesiredSize

只读Gets the size that this UIElement computed during the measure pass of the layout process. (继承自UIElement)

Dispatcher

只读Gets the CoreDispatcher that this object is associated with. (继承自DependencyObject)

FlowDirection

读/写Gets or sets the direction in which text and other UI elements flow within any parent element that controls their layout. This property can be set to either LeftToRight or RightToLeft. Setting FlowDirection to RightToLeft on any element sets the alignment to the right, the reading order to right-to-left and the layout of the control to flow from right to left. (继承自FrameworkElement)

FocusState

只读Gets a value that specifies whether this control has focus, and the mode by which focus was obtained. (继承自Control)

FontFamily

读/写Gets or sets the font used to display text in the control. (继承自Control)

FontSize

读/写Gets or sets the size of the text in this control. (继承自Control)

FontStretch

读/写Gets or sets the degree to which a font is condensed or expanded on the screen. (继承自Control)

FontStyle

读/写Gets or sets the style in which the text is rendered. (继承自Control)

FontWeight

读/写Gets or sets the thickness of the specified font. (继承自Control)

Foreground

读/写Gets or sets a brush that describes the foreground color. (继承自Control)

Height

读/写Gets or sets the suggested height of a FrameworkElement. (继承自FrameworkElement)

HorizontalAlignment

读/写Gets or sets the horizontal alignment characteristics that are applied to a FrameworkElement when it is composed in a layout parent, such as a panel or items control. (继承自FrameworkElement)

HorizontalContentAlignment

读/写Gets or sets the horizontal alignment of the control's content. (继承自Control)

IsDoubleTapEnabled

读/写Gets or sets a value that determines whether the DoubleTapped event can originate from that element. (继承自UIElement)

IsEnabled

读/写Gets or sets a value indicating whether the user can interact with the control. (继承自Control)

IsHitTestVisible

读/写Gets or sets whether the contained area of this UIElement can return true values for hit testing. (继承自UIElement)

IsHoldingEnabled

读/写Gets or sets a value that determines whether the Holding event can originate from that element. (继承自UIElement)

IsOpen

读/写Gets or sets a value that indicates whether the AppBar is visible. (继承自AppBar)

IsRightTapEnabled

读/写Gets or sets a value that determines whether the RightTapped event can originate from that element. (继承自UIElement)

IsSticky

读/写Gets or sets a value that indicates whether the AppBar does not close on light dismiss. (继承自AppBar)

IsTabStop

读/写Gets or sets a value that indicates whether a control is included in tab navigation. (继承自Control)

IsTapEnabled

读/写Gets or sets a value that determines whether the Tapped event can originate from that element. (继承自UIElement)

Language

读/写Gets or sets localization/globalization language information that applies to a FrameworkElement, and also to all child elements of the current FrameworkElement in the object representation and in UI. (继承自FrameworkElement)

ManipulationMode

读/写Gets or sets the ManipulationModes value used for UIElement behavior and interaction with gestures. Setting this value enables handling the manipulation events from this element in app code. (继承自UIElement)

Margin

读/写Gets or sets the outer margin of a FrameworkElement. (继承自FrameworkElement)

MaxHeight

读/写Gets or sets the maximum height constraint of a FrameworkElement. (继承自FrameworkElement)

MaxWidth

读/写Gets or sets the maximum width constraint of a FrameworkElement. (继承自FrameworkElement)

MinHeight

读/写Gets or sets the minimum height constraint of a FrameworkElement. (继承自FrameworkElement)

MinWidth

读/写Gets or sets the minimum width constraint of a FrameworkElement. (继承自FrameworkElement)

Name

读/写Gets or sets the identifying name of the object. When a XAML processor creates the object tree from XAML markup, run-time code can refer to the XAML-declared object by this name. (继承自FrameworkElement)

Opacity

读/写Gets or sets the degree of the object's opacity. (继承自UIElement)

Padding

读/写Gets or sets the padding inside a control. (继承自Control)

Parent

只读Gets the parent object of this FrameworkElement in the object tree. (继承自FrameworkElement)

PointerCaptures

只读Gets the set of all captured pointers, represented as Pointer values. (继承自UIElement)

PrimaryCommands

只读Gets the collection of primary command elements for the CommandBar.

PrimaryCommandsProperty

只读Identifies the PrimaryCommands dependency property.

Projection

读/写Gets or sets the perspective projection (3-D effect) to apply when rendering this element. (继承自UIElement)

RenderSize

只读Gets the final render size of a UIElement. (继承自UIElement)

RenderTransform

读/写Gets or sets transform information that affects the rendering position of a UIElement. (继承自UIElement)

RenderTransformOrigin

读/写Gets or sets the origin point of any possible render transform declared by RenderTransform, relative to the bounds of the UIElement. (继承自UIElement)

RequestedTheme

读/写Gets or sets the UI theme that is used by the UIElement (and its child elements) for resource determination. The UI theme you specify with RequestedTheme can override the app-level RequestedTheme. (继承自FrameworkElement)

Resources

读/写Gets the locally defined resource dictionary. In XAML, you can establish resource items as child object elements of a frameworkElement.Resources property element, through XAML implicit collection syntax. (继承自FrameworkElement)

SecondaryCommands

只读Gets the collection of secondary command elements for the CommandBar.

SecondaryCommandsProperty

只读Identifies the SecondaryCommands dependency property.

Style

读/写Gets or sets an instance Style that is applied for this object during layout and rendering. (继承自FrameworkElement)

TabIndex

读/写Gets or sets a value that determines the order in which elements receive focus when the user navigates through controls by pressing the Tab key. (继承自Control)

TabNavigation

读/写Gets or sets a value that modifies how tabbing and TabIndex work for this control. (继承自Control)

Tag

读/写Gets or sets an arbitrary object value that can be used to store custom information about this object. (继承自FrameworkElement)

Template

读/写Gets or sets a control template. The control template defines the visual appearance of a control in UI, and is defined in XAML markup. (继承自Control)

Transitions

读/写Gets or sets the collection of Transition style elements that apply to a UIElement. (继承自UIElement)

Triggers

只读Gets the collection of triggers for animations that are defined for a FrameworkElement. Not commonly used. (继承自FrameworkElement)

UseLayoutRounding

读/写Gets or sets a value that determines whether rendering for the object and its visual subtree should use rounding behavior that aligns rendering to whole pixels. (继承自UIElement)

VerticalAlignment

读/写Gets or sets the vertical alignment characteristics that are applied to a FrameworkElement when it is composed in a parent object such as a panel or items control. (继承自FrameworkElement)

VerticalContentAlignment

读/写Gets or sets the vertical alignment of the control's content. (继承自Control)

Visibility

读/写Gets or sets the visibility of a UIElement. A UIElement that is not visible is not rendered and does not communicate its desired size to layout. (继承自UIElement)

Width

读/写Gets or sets the width of a FrameworkElement. (继承自FrameworkElement)

 

备注

CommandBar 通过提供以下内容,简化基本应用程序栏的创建:

  • 对右侧的主要命令和左侧的辅助命令进行自动命令布局。
  • 当应用程序大小更改时,自动调整应用程序栏命令。

当你需要只包含 AppBarButtonAppBarToggleButtonAppBarSeparator 控件的应用程序栏时,应使用 CommandBar。如果需要更复杂的内容,例如图像、进度条或文本块,请使用 AppBar 控件。

默认情况下,你添加到 CommandBar 的项会添加到 PrimaryCommands 集合。 这些命令显示在 CommandBar 的右侧。你可以将命令添加到 SecondaryCommands 集合,并且这些项将在左侧显示。(排序是相反,当 FlowDirectionRightToLeft。)

应用程序栏按钮控件有两种大小:普通和紧凑。默认情况下,它们有文本标签以及完整的填充。当 IsCompact 属性设置为 true 时,将隐藏文本标签,并将减小按钮周围的内边距。AppBarSeparator 还具有一个紧凑状态,其中的填充会减小。在 CommandBar 控件中使用时,CommandBar 在空间不足无法显示全尺寸的命令时自动设置 IsCompact 属性。

下面是后面所示的示例代码创建的 CommandBar

命令栏

下面是当应用程序具有较少空间时的相同 CommandBarCommandBar 自动为其按钮设置 IsCompact 属性,以缩小它们占用的空间。

包含紧凑按钮的命令栏

如果 CommandBar 没有足够的空间以简洁状态显示所有按钮,则它会隐藏 SecondaryCommands

示例

此示例创建前面显示的命令栏。


<Page.BottomAppBar>
    <CommandBar>
        <AppBarToggleButton Icon="Shuffle" Label="Shuffle" Click="AppBarButton_Click"/>
        <AppBarToggleButton Icon="RepeatAll" Label="Repeat" Click="AppBarButton_Click"/>
        <AppBarSeparator/>
        <AppBarButton Icon="Back" Label="Back" Click="AppBarButton_Click"/>
        <AppBarButton Icon="Stop" Label="Stop" Click="AppBarButton_Click"/>
        <AppBarButton Icon="Play" Label="Play" Click="AppBarButton_Click"/>
        <AppBarButton Icon="Forward" Label="Forward" Click="AppBarButton_Click"/>

        <CommandBar.SecondaryCommands>
            <AppBarButton Icon="Like" Label="Like" Click="AppBarButton_Click"/>
            <AppBarButton Icon="Dislike" Label="Dislike" Click="AppBarButton_Click"/>
        </CommandBar.SecondaryCommands>
    </CommandBar>
</Page.BottomAppBar>

要求

最低支持客户端

Windows 8.1 [仅 Windows 应用商店应用程序]

最低支持服务器

Windows Server 2012 R2 [仅 Windows 应用商店应用程序]

命名空间

Windows.UI.Xaml.Controls
Windows::UI::Xaml::Controls [C++]

元数据

Windows.winmd

另请参见

AppBar
AppBarButton
AppBarToggleButton
AppBarSeparator

 

 

显示:
© 2014 Microsoft