ButtonBase.Click Evento
Definizione
public:
event System::Windows::RoutedEventHandler ^ Click;
public event System.Windows.RoutedEventHandler Click;
member this.Click : System.Windows.RoutedEventHandler
Public Custom Event Click As RoutedEventHandler
Esempi
Nell'esempio seguente vengono illustrati tre pulsanti che rispondono ai clic in tre modi diversi.The following example shows three buttons that respond to clicks in three different ways.
Hover: il primo pulsante modifica i colori quando l'utente passa il mouse sul pulsanteHover - the first button changes colors when the user hovers with the mouse over the button
Premere: il secondo pulsante richiede che il mouse venga premuto mentre il puntatore del mouse si trova nel pulsante.Press - the second button requires that the mouse be pressed while the mouse pointer is in the button.
Versione: il terzo non reimposta il colore di sfondo dei pulsanti fino a quando il mouse non viene premuto e rilasciato nel pulsante.Release - the third does not reset the background color of the buttons until the mouse is pressed and released in the button.
<Button Name="btn1" Background="Pink"
BorderBrush="Black" BorderThickness="1"
Click="OnClick1" ClickMode="Hover">
ClickMe1
</Button>
<Button Name="btn2" Background="LightBlue"
BorderBrush="Black" BorderThickness="1"
Click="OnClick2" ClickMode="Press">
ClickMe2
</Button>
<Button Name="btn3"
Click="OnClick3" ClickMode="Release">
Reset
</Button>
void OnClick1(object sender, RoutedEventArgs e)
{
btn1.Background = Brushes.LightBlue;
}
void OnClick2(object sender, RoutedEventArgs e)
{
btn2.Background = Brushes.Pink;
}
void OnClick3(object sender, RoutedEventArgs e)
{
btn1.Background = Brushes.Pink;
btn2.Background = Brushes.LightBlue;
}
Private Sub OnClick1(ByVal sender As Object, ByVal e As RoutedEventArgs)
btn1.Background = Brushes.LightBlue
End Sub
Private Sub OnClick2(ByVal sender As Object, ByVal e As RoutedEventArgs)
btn2.Background = Brushes.Pink
End Sub
Private Sub OnClick3(ByVal sender As Object, ByVal e As RoutedEventArgs)
btn1.Background = Brushes.Pink
btn2.Background = Brushes.LightBlue
End Sub
Commenti
L'utente può generare l' Click evento AccessText usando o premendo invio o la barra spaziatrice quando il controllo ha lo stato attivo.The user can raise the Click event by using an AccessText or by pressing ENTER or the SPACEBAR when the control has focus. Quando l'utente preme la barra spaziatrice, il controllo IsPressed imposta true
e acquisisce il mouse.When the user presses the SPACEBAR, the control sets IsPressed to true
and captures the mouse. Di conseguenza, il controllo genererà eventi del mouse, ad MouseEnter esempio IsMouseDirectlyOverChangede.As a result, the control will raise mouse events such as MouseEnter and IsMouseDirectlyOverChanged. Si noti che l' AccessText uso di o di invio IsPressed non modifica o acquisisce il mouse, ma genera Click l'evento.Note that using the AccessText or ENTER does not change IsPressed or capture the mouse, but it does raise the Click event.
Contrassegna l' MouseLeftButtonDowneventocome gestito nel metodoeClick genera l'evento. OnMouseLeftButtonDown ButtonBaseThe ButtonBase marks the MouseLeftButtonDown event as handled in the OnMouseLeftButtonDown method and raises the Click event. Di conseguenza, OnMouseLeftButtonDown l'evento non si verificherà mai per un controllo ButtonBaseche eredita da.Hence, the OnMouseLeftButtonDown event will never occur for a control that inherits from ButtonBase. Al contrario, associare un gestore eventi all' PreviewMouseLeftButtonDown evento o chiamare AddHandler(RoutedEvent, Delegate, Boolean) con handledEventsToo
impostato su true
.Instead, attach an event handler to the PreviewMouseLeftButtonDown event, or call AddHandler(RoutedEvent, Delegate, Boolean) with handledEventsToo
set to true
.
Informazioni evento indirizzatoRouted Event Information
Campo identificatoreIdentifier field | ClickEvent |
Strategia di routingRouting strategy | BubblingBubbling |
delegatoDelegate | RoutedEventHandler |