FrameworkContentElement.Cursor Proprietà

Definizione

Recupera o imposta il cursore visualizzato quando il puntatore del mouse è posizionato sull'elemento.

public:
 property System::Windows::Input::Cursor ^ Cursor { System::Windows::Input::Cursor ^ get(); void set(System::Windows::Input::Cursor ^ value); };
public System.Windows.Input.Cursor Cursor { get; set; }
member this.Cursor : System.Windows.Input.Cursor with get, set
Public Property Cursor As Cursor

Valore della proprietà

Cursore da visualizzare. Il valore predefinito è definito come null in base a questa proprietà di dipendenza. Tuttavia, l'impostazione predefinita pratica in fase di esecuzione dipenderà da numerosi fattori.

Esempio

Nell'esempio seguente il cursore viene impostato su un valore personalizzato.

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;
        }
    }
}
' When the Radiobox changes, a new cursor type is set
Private Sub CursorTypeChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)

    Dim item As String = CType(e.Source, ComboBox).SelectedItem.Content.ToString()

    Select Case item
        Case "AppStarting"
            DisplayArea.Cursor = Cursors.AppStarting
        Case "ArrowCD"
            DisplayArea.Cursor = Cursors.ArrowCD
        Case "Arrow"
            DisplayArea.Cursor = Cursors.Arrow
        Case "Cross"
            DisplayArea.Cursor = Cursors.Cross
        Case "HandCursor"
            DisplayArea.Cursor = Cursors.Hand
        Case "Help"
            DisplayArea.Cursor = Cursors.Help
        Case "IBeam"
            DisplayArea.Cursor = Cursors.IBeam
        Case "No"
            DisplayArea.Cursor = Cursors.No
        Case "None"
            DisplayArea.Cursor = Cursors.None
        Case "Pen"
            DisplayArea.Cursor = Cursors.Pen
        Case "ScrollSE"
            DisplayArea.Cursor = Cursors.ScrollSE
        Case "ScrollWE"
            DisplayArea.Cursor = Cursors.ScrollWE
        Case "SizeAll"
            DisplayArea.Cursor = Cursors.SizeAll
        Case "SizeNESW"
            DisplayArea.Cursor = Cursors.SizeNESW
        Case "SizeNS"
            DisplayArea.Cursor = Cursors.SizeNS
        Case "SizeNWSE"
            DisplayArea.Cursor = Cursors.SizeNWSE
        Case "SizeWE"
            DisplayArea.Cursor = Cursors.SizeWE
        Case "UpArrow"
            DisplayArea.Cursor = Cursors.UpArrow
        Case "WaitCursor"
            DisplayArea.Cursor = Cursors.Wait
        Case "Custom"
            DisplayArea.Cursor = CustomCursor
    End Select

    ' if the cursor scope is set to the entire application
    ' use OverrideCursor to force the cursor for all elements
    If (cursorScopeElementOnly = False) Then
        Mouse.OverrideCursor = DisplayArea.Cursor
    End If


End Sub

Commenti

Quando si imposta questa proprietà in XAML, il processore XAML si basa sulla conversione dei tipi per la Cursor classe per valutare la stringa. La stringa specificata deve restituire un CursorType valore. Per informazioni dettagliate, vedere Cursor.

Indipendentemente dal fatto che il cursore stabilito da questa proprietà venga visualizzato o meno quando il puntatore del mouse si trova su questo elemento dipende anche dal valore della ForceCursor proprietà. Inoltre, considerazioni relative agli eventi, ad esempio un trascinamento attivo, l'acquisizione del mouse, le modalità di modifica del testo all'interno dei controlli e così via, influiranno anche sul cursore con priorità più alta rispetto al valore specificato in questa proprietà.

Per ripristinare il comportamento dell'impostazione di questa proprietà sul valore predefinito finale, impostarlo di nuovo su null .

Il null valore predefinito significa realmente che la determinazione del valore pratico del cursore viene posticipata qui e deve essere ottenuta da un'altra posizione. Se non viene visualizzato alcun valore programmatico da alcuna origine, il cursore predefinito su un'applicazione Windows Presentation Foundation (WPF) sarà una freccia.

Ogni spostamento del mouse su un'applicazione WPF genera un QueryCursor evento. Le bolle di evento e qualsiasi elemento lungo la route ha la possibilità di gestire l'evento e di impostare il valore del cursore tramite gli argomenti di questo evento. In tal caso, il fatto che l'evento venga gestito e abbia un valore modificato negli argomenti ha la precedenza sul valore della Cursor proprietà a qualsiasi livello, a meno che non ForceCursor sia impostato.

Se non si crea un cursore personalizzato, in genere questa proprietà viene impostata su un valore di proprietà statica della Cursors classe .

L'impostazione di su Cursor un valore personalizzato non è abilitata in attendibilità parziale. Per altre informazioni sui cursori personalizzati, vedere Panoramica dell'input.

Informazioni proprietà di dipendenza

Campo Identificatore CursorProperty
Proprietà dei metadati impostate su true Nessuno

Si applica a

Vedi anche