共用方式為


ToolTipService.Placement Attached Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the position of the tooltip in relation to its target visual element.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
See GetPlacement, SetPlacement
See GetPlacement, SetPlacement
<object ToolTipService.Placement="placementModeValue"/>

XAML Values

  • placementModeValue
    A named constant of the PlacementMode enumeration, such as Left.

Property Value

Type: System.Windows.Controls.Primitives.PlacementMode
The position of the tooltip in relation to its target visual element.

Remarks

Setting the Placement property on ToolTipService takes precedence over the Placement value of ToolTip, when the tooltip is activated with the mouse.

If the tooltip does not fit within the bounds of the Silverlight plug-in at the specified placement, it is automatically moved to a location where it fits. The tooltip is first moved to the opposite location of the specified placement, and then to the other locations in a top-to-bottom, left-to-right order. If the tooltip does not fit completely at the top, bottom, left, or right of the target element, the tooltip is positioned at the right and is clipped. For example, if you specify Top, and the tooltip does not fit within the bounds of the plug-in at the top of the target element, the tooltip is moved to the bottom of the target. If it does not fit at the bottom, it is moved to the left, and if it does not fit at the left it is moved to the right of the target.

If the tooltip exceeds the width of the browser, it is clipped.

If the tooltip is automatically moved, the Placement value for the ToolTip or ToolTipService is not changed

Dependency property identifier field: ToolTipProperty

Examples

The following code example demonstrates the placement modes for a tooltip.

Run this sample

<Border BorderThickness="3" BorderBrush="Black">
    <StackPanel Background="LightGray">
        <TextBlock  Text="ToolTip Control" Margin="5" />
        <StackPanel x:Name="LayoutRoot"  Orientation="Horizontal">
            <TextBlock TextWrapping="Wrap" Width="150" Text="Hover over an item to see its ToolTip: " 
                Margin="5" VerticalAlignment="Center" />
                <ListBox Width="100" x:Name="myListBox" ToolTipService.ToolTip="ToolTip" 
                    ToolTipService.Placement="Right" >
                <ListBox.Items>
                    <ListBoxItem Content="Left" ToolTipService.ToolTip="ToolTip to the left." 
                        ToolTipService.Placement="Left" />
                    <ListBoxItem Content="Right" ToolTipService.ToolTip="ToolTip to the right." 
                        ToolTipService.Placement="Right" />
                    <ListBoxItem Content="Top" ToolTipService.ToolTip="ToolTip at the top." 
                        ToolTipService.Placement="Top" />
                    <ListBoxItem Content="Bottom" ToolTipService.ToolTip="ToolTip at the bottom." 
                        ToolTipService.Placement="Bottom"/>
                    <ListBoxItem Content="Mouse" ToolTipService.ToolTip="ToolTip based on the mouse." 
                        ToolTipService.Placement="Mouse"/>
                </ListBox.Items>
                </ListBox>
        </StackPanel>
    </StackPanel>
</Border>

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.