Dieser Artikel wurde maschinell übersetzt. Wenn Sie die englische Version des Artikels anzeigen möchten, aktivieren Sie das Kontrollkästchen Englisch. Sie können den englischen Text auch in einem Popupfenster anzeigen, indem Sie den Mauszeiger über den Text bewegen.
Übersetzung
Englisch

FrameworkElement.Cursor-Eigenschaft

 

Veröffentlicht: Oktober 2016

Ruft den Cursor ab bzw. legt den Cursor fest, der angezeigt wird, wenn sich der Mauszeiger über diesem Element befindet.

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

public Cursor Cursor { get; set; }

Eigenschaftswert

Type: System.Windows.Input.Cursor

Der anzuzeigende Cursor. Der Standardwert ist gemäß dieser Abhängigkeitseigenschaft als null definiert. Der zur Laufzeit angewendete Standardwert resultiert jedoch aus einer Vielzahl von Faktoren.

When you set this property in TLA2#tla_xaml, the TLA2#tla_xaml processor relies on type conversion for the T:System.Windows.Input.Cursor class to evaluate the string. The provided string should evaluate to a T:System.Windows.Input.CursorType value. See T:System.Windows.Input.Cursor for details.

Whether the cursor as established by this property will or will not display when the mouse pointer is over this element is also dependent on the value of the P:System.Windows.FrameworkElement.ForceCursor property. Also, event-related considerations such as an active drag, mouse capture, text editing modes within controls, and so on, will also affect the cursor with higher priority than the value you specify in this property.

To revert the behavior of setting this property to the eventual default, set it to null again.

The null default really means that determination of the practical cursor value is deferred here and should be obtained from elsewhere. If presented without programmatic values from any source, the default cursor that is visually over a TLA#tla_winclient application will be an arrow. However, the transient cursor changes are not set to the P:System.Windows.FrameworkElement.Cursor values of the elements when they are passed over. The P:System.Windows.FrameworkElement.Cursor property will only report non null values in cases where it was actually set, for instance through code or a style. Each movement of the mouse over a TLA2#tla_winclient application raises a E:System.Windows.UIElement.QueryCursor event. The event bubbles, and any element along the route has the opportunity to handle the event and to set the value of the cursor through the arguments of this event. This is the mechanism that produces the visually apparent cursor in most cases. If a E:System.Windows.UIElement.QueryCursor handler returns a cursor result, then the fact that the event is handled and has a changed value in the arguments takes precedence over the value of the P:System.Windows.FrameworkElement.Cursor property at any level, unless P:System.Windows.FrameworkElement.ForceCursor is set.

If not are not creating a custom cursor, you typically set this property to a static property value of the T:System.Windows.Input.Cursors class. Setting P:System.Windows.FrameworkElement.Cursor in code requires one of the following:

  • Call the T:System.Windows.Input.Cursor constructor to get a T:System.Windows.Input.Cursor instance. Both signatures of the T:System.Windows.Input.Cursor constructor use streams or files, in anticipation that you are creating the T:System.Windows.Input.Cursor object for a custom cursor.

  • Use the T:System.Windows.Input.CursorConverter class and its M:System.Windows.Input.CursorConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext,System.Globalization.CultureInfo,System.Object) method to specify a cursor by T:System.Windows.Input.CursorType, or a string that can evaluate to a T:System.Windows.Input.CursorType, and cast the return to T:System.Windows.Input.Cursor.

Setting the T:System.Windows.Input.Cursor to a custom value is not enabled in partial trust. For more information on custom cursors, see Input Overview.

Identifier field

CursorProperty

Metadata properties set to true

None

The following example shows how to deliberately set the cursor graphic.

private void CursorTypeChanged(object sender, SelectionChangedEventArgs e)
{
    ComboBox source = e.Source as ComboBox;

    if (source != null)
    {
        ComboBoxItem selectedCursor = source.SelectedItem as ComboBoxItem;

        // Changing the cursor of the Border control 
        // by setting the Cursor property
        switch (selectedCursor.Content.ToString())
        {
            case "AppStarting":
                DisplayArea.Cursor = Cursors.AppStarting;
                break;
            case "ArrowCD":                        
                DisplayArea.Cursor = Cursors.ArrowCD;
                break;
            case "Arrow":
                DisplayArea.Cursor = Cursors.Arrow;
                break;
            case "Cross":
                DisplayArea.Cursor = Cursors.Cross;
                break;
            case "HandCursor":
                DisplayArea.Cursor = Cursors.Hand;
                break;
            case "Help":
                DisplayArea.Cursor = Cursors.Help;
                break;
            case "IBeam":
                DisplayArea.Cursor = Cursors.IBeam;
                break;
            case "No":
                DisplayArea.Cursor = Cursors.No;
                break;
            case "None":
                DisplayArea.Cursor = Cursors.None;
                break;
            case "Pen":
                DisplayArea.Cursor = Cursors.Pen;
                break;
            case "ScrollSE":
                DisplayArea.Cursor = Cursors.ScrollSE;
                break;
            case "ScrollWE":
                DisplayArea.Cursor = Cursors.ScrollWE;
                break;
            case "SizeAll":
                DisplayArea.Cursor = Cursors.SizeAll;
                break;
            case "SizeNESW":
                DisplayArea.Cursor = Cursors.SizeNESW;
                break;
            case "SizeNS":
                DisplayArea.Cursor = Cursors.SizeNS;
                break;
            case "SizeNWSE":
                DisplayArea.Cursor = Cursors.SizeNWSE;
                break;
            case "SizeWE":
                DisplayArea.Cursor = Cursors.SizeWE;
                break;
            case "UpArrow":
                DisplayArea.Cursor = Cursors.UpArrow;
                break;
            case "WaitCursor":
                DisplayArea.Cursor = Cursors.Wait;
                break;
            case "Custom":
                DisplayArea.Cursor = CustomCursor;
                break;
            default:
                break;
        }

        // If the cursor scope is set to the entire application
        // Use OverrideCursor to force the cursor for all elements
        if (cursorScopeElementOnly == false)
        {
            Mouse.OverrideCursor = DisplayArea.Cursor;
        }
    }
}

.NET Framework
Verfügbar seit 3.0
Silverlight
Verfügbar seit 2.0
Windows Phone Silverlight
Verfügbar seit 7.0
Zurück zum Anfang
Anzeigen: