質問

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)
{
   ...
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top