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);
문제
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.
해결책
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);
다른 팁
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)
{
...
}