1

Is it possible to select items of the same type like jQuery selector in WPF?

    <div class="good">123<div>
    <div class="good">234<div>
    <div class="good">345<div>
    <div>aaa<div>

By jQuery, we can select all the div's of class "good" by $('.good').

For WPF, it is possible to do the selection like that by adding some sort of class to control?

ps: what i m doing is trying to change the style of a few controls from code behind. currently, i have made it by changing the style that has been applied to controls. at the moment, i think over it and have the question if WPF support this jQuery Style selection. Anyway, in WPF, it seems not a good idea to do in javascript way.

David Guo
  • 90
  • 6
  • To answer your precision of your question, no, WPF has no way to select controls like jQuery. And as you say, it's not usually a good idea to do it the javascript way. WPF paradigm is way different than the one behind jQuery/js/DOM manipulation. Usually in WPF when in code behind, you should not have to worry about where a value come from. – Sebastien F. Nov 08 '12 at 13:13

2 Answers2

1

You can do something in that spirit (see this question) but I have the feeling that you are on the path of trying to do WPF like you do Javascript, which might not be the best way to do it.

If it's the case I would recommend to look into MVVM, and especially this article which, with its exemple, is the best I ever found on that topic.

Community
  • 1
  • 1
Sebastien F.
  • 1,613
  • 2
  • 23
  • 40
1

In wpf there is a visual tree (representation of visual elements in top container) you can search and select elements in visual tree using for example VisualTreeHelper class ,

see ref http://wpftutorial.net/LogicalAndVisualTree.html

But I'd not suggest to do this , this is not the way of changing elements in wpf. Explain exactly what you need to do , I will try to point to the place.

StringBuilder
  • 1,619
  • 4
  • 32
  • 52
  • thx a lot. i v add some comment directly to my question. surely, it is not a good idea to do the javascript way. – David Guo Nov 08 '12 at 09:55