I'm learning WPF, and am wondering if there's an idiomatic way to create a label that, when clicked, toggles a checkbox or radio button. I was somewhat surprised that the Target attribute on Label doesn't do this. I am using the MVVM pattern (with the MVVMFoundation framework.)
Asked
Active
Viewed 1,801 times
3
davidtbernal
- 13,073
- 9
- 43
- 59
-
Do you mean clicking on the content (for example a text label) of a checkbox or radiobutton should set it as checked? Isn't that how it works by default? – Wallstreet Programmer Jun 22 '10 at 18:12
-
Oh my. I didn't realize you can set the content of a radiobutton or checkbox, how embarassing. I've been thinking like a web developer. – davidtbernal Jun 22 '10 at 19:58
-
There's a good example [at this question](http://stackoverflow.com/questions/681960/wpf-label-counterpart-for-html-for-attribute). – Beau May 13 '11 at 00:03
1 Answers
3
The target property sets the focus to the target element when the labels pre-defined access key is pressed so does not do what you want.
Off the top of my head I would suggest creating a button and using a Style to make it look like a label. You can add 'content' to a checkbox though and this will check the box when clicked.
Leom Burke
- 8,040
- 1
- 34
- 30