Pergunta

I want to add a click event handler when a WPF label is clicked. The idea is to do it code behind, because I´m generating the interface dynamically base on a document.

Foi útil?

Solução

If I understand this correctly, you want a Label with a LeftMouseDown-event, which you would write from code?

In that case:

TestLabel.MouseLeftButtonDown += new MouseButtonEventHandler(TARGET);

Outras dicas

Since you've mentioned code behind, you can listen for the Label's PreviewMouseLeftButtonUp event since a Label control does not have a Click event associated with it.

Example:

var label = new Label();
label.PreviewMouseLeftButtonUp += LabelMouseLeftButtonUp;    

// Handler
private void LabelMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
   ...
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top