See Sharp
Is it really just a matter of point of view ?

it's PART_Ytime, baby !

August 29, 2008 12:23 by salfab

Introduction 

Aujourd'hui, jettons un oeil à ces étranges Named Template Parts que l'on peut parfois voir dans les Templates de certains contrôles, et qui sont facilement reconnaissable au préfixe PART_

Qu'est-ce que ce PART_ ?

De façon à pouvoir rendre un CustomControl hautement Templateable (Anglicisme fait maison qui signifie "un truc qu'on peut lui appliquer un template dessus"), il va nous falloir poser quelques contraintes. En effet : Si l'utilisateur de notre contrôle peut entièrement le re-templater, qui nous assure qu'un certain élément sur lequel nous nous reposons est toujours existant ?

Exemple : SalFab crée une TextBox en 3D. Ce contrôle s'appelle évidemment SalFab3DTextBox, et contient dans son template par défaut, en plus de tout l'attirail nécessaire à la gestion de la 3D, un élément TextBox qui contiendra le texte à entrer - Le nerf de la guerre. Comme SalFab désire ardemment que tout le monde utilise son contrôle, il décide de permettre au monde entier de changer le template de son contrôle. Comment être sûr que l'utilisateur utilise bel et bien un élément TextBox dans son template ? Rappellons que toute la logique du contrôle se repose sur le postulat qu'il existe un tel élément dans son template !

L'idée est de donner un nom prédéfini à cet élément ( grâce à la propriété x:Name du TextBox ), par exemple, "PART_UnderLyingTextBox". Afin de pouvoir travailler avec dans le codebehind, nous aimerions en récupérer une référence. Ceci peut se faire dans la méthode OnApplyTemplate de notre contrôle, grâce à un appel de la méthode GetTemplateChild("PART_UnderLyingTextBox"). Le paramètre de la méthode est bien entendu le nom, arbitraire, de notre élément. Il nous sera alors possible de lui appliquer la logique applicative désirée. Par exemple, enregistrer son évènement TextChanged. On pourra également tester si le retour de GetTemplateChild est null, et adapter le comportement du contrôle en conséquence.

Si le nom à donner à x:Name est bien arbitraire, l'usage veut que pour ce genre d'utilisation, l'on utilise le préfixe PART_.

Notons qu'il ne s'agit pas là d'un nom réservé, mais d'une convention de codage. Par conséquent, il sera judicieux de documenter explicitement les Parts utilisées par notre contrôle, chose qui peut être faite à l'aide de l'attribut TemplatePartAttribute

Par exemple, dans notre cas :

[TemplatePart(Name = "PART_UnderLyingTextBox", Type = typeof(TextBox))]

Notons finalement que l'attribut TemplatePartAttribute n'applique aucun comportement, mais est uniquement présent pour décrire les parts utilisées. Cet attribut ser utilisé par des outils de design pour mettre en évidence leur existence.

 Happy Templating !


Comments

August 29. 2008 20:22

fgeo

Ca tombe bien, vais devoir faire de gros Templates bientôt, merci d'avoir percé le secret des PART_ Smile

fgeo

August 11. 2009 01:44

cash loans

Interesting article. Were did you got all the information from... Smile

cash loans

August 16. 2009 07:23

Celebrities Graphiocs

thanks for this usefull informations..
finally i find something that i want to know..
this article is very usefull..

Celebrities Graphiocs

August 28. 2009 05:59

bad credit loans

What is captcha code?, pls provide me captcha code codes or plugin, Thanks in advance.

bad credit loans

March 4. 2010 07:09

hd movies

I enjoy watching movies online, it is way easier than going to the theaters.

hd movies

March 13. 2010 05:47

Latest news

Hi, this was a really quality blog. I'd like to write like this also - taking time and real effort to make a good article... but what can I say... I Am lazy and never seem to get something done.

Latest news

March 27. 2010 00:46

payday loans fast

Have you ever considered adding more videos to your blog posts to keep the readers more entertained? I mean I just read through the entire article of yours and it was quite good but since I'm more of a visual learner,I found that to be more helpful well let me know how it turns out!

payday loans fast

March 27. 2010 15:52

check cash advance

Aw, this was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article... but what can I say... I procrastinate alot and never seem to get something done.

check cash advance

March 28. 2010 23:33

quick approval loans

Have you ever considered adding more videos to your blog posts to keep the readers more entertained? I mean I just read through the entire article of yours and it was quite good but since I'm more of a visual learner,I found that to be more helpful well let me know how it turns out!

quick approval loans

May 4. 2010 04:03

Hotels

Thanks for the information, i posted your blog to my facebook group in the category `See Sharp | it's PART_Ytime, baby !`. Regards, Katy

Hotels

May 6. 2010 15:02

Merle Troike

I Fully understand what your position in this matter is. While I should disagree on some of the smaller details, I suppose you did an impressive job outlining it. Definitely beats the need to research it on my own. Thanks.

Merle Troike

May 7. 2010 16:23

Power Trainer

If you're interested in having a guest blog poster please reply and let me know, also if you want to have a guest account on my blog. Cheers, Dave the Power Trainer

Power Trainer

May 8. 2010 15:30

Mariana

Bookmarked, i will add your homepage to my toolbar

Mariana

May 8. 2010 20:40

play games

Can you pleasee make available extra information about this subject?? BTW your site is amazing. Best regards..

play games

May 12. 2010 09:32

Shawn

Way to go I will keep checkin in!

Shawn

May 13. 2010 11:26

parent

Your posts are always great, keep them coming.

parent

May 14. 2010 11:30

Zikk

yo good blog and nice work our blog video newspaper will soon be adding reviews on blogs and add them to our as the top best 1000 blogs to visit we also do video reviews on See Sharp | it's PART_Ytime, baby !  and all types of reviews go here

Zikk

May 15. 2010 13:23

Anabel Brookfield

Wow, I didn’t knew this, thanks.

Anabel Brookfield

May 20. 2010 00:52

Wahdo

After reading the article, I feel that I need more information on the topic. Can you suggest some resources please?

Wahdo

May 21. 2010 19:11

Laverne Hocutt

I think that is an interesting point, it made me think a bit.  Thanks for sparking my thinking cap.See Sharp | it's PART_Ytime, baby ! was a wonderful read.

Laverne Hocutt

May 22. 2010 05:24

Loan Mod

OK, first I'd like to say that See Sharp | it's PART_Ytime, baby ! is good and the web need more articles like it.  Not to get off on any tangents but health insurance reform, earth quakes, cheating celebs, arg!!! I forget by reading blogs like this. Peace out.

Loan Mod

May 23. 2010 11:13

Lewis Ericks

I thought it was going to be some boring old post, but it really compensated for my time. I will post a link to this page on my blog. I am sure my visitors will find that very useful

Lewis Ericks

May 27. 2010 11:50

chainsaws

Useful information, many thanks to the author. It is puzzling to me now, but in general, the usefulness and importance is overwhelming. Very much thanks again and good luck!

chainsaws

May 30. 2010 01:03

Devin Timmers

Kids are so precious and only should be taken care of in that way!  Your blog has allowed me to think up some interesting ideas, so thank you and please keep it coming!

Devin Timmers

June 6. 2010 23:14

how to use playstation 3 controller on pc

Great post & Fantastic blog! I would definitely love to begin a blog too but I have no clue where to begin. I possess the ability to do it (not that challenging on the technical part) but I really feel like I am too lazy to post regularly. That is the problem, if you start you have to go all the way. However blogs like yours inspire me to have a go at it.

how to use playstation 3 controller on pc

June 7. 2010 09:46

lily baby bedding

I really loved reading your blog. It was very well authored and easy to undertand. Unlike additional blogs I have read which are really not tht good. I also found your entries very interesting. In fact after reading, I had to go show it to my friend and he ejoyed it as well!

lily baby bedding

June 8. 2010 03:44

the resistance Lyrics

Hey this is a great story. I'm going to email this to my friends. I stumbled on this while surfing for some lyrics, I'll be sure to come back. thanks for sharing.

the resistance Lyrics

June 27. 2010 17:23

xbox membership

Greetings from Montana!  Just came across your blog.  Actually took in your article, I'll email it along! :-P  Have a great day!

xbox membership

July 7. 2010 20:47

Top 10 Job Interview Questions

Hey Webmaster, I like MS Blog Engine but why did you chose it?  I mean it's so neat with the random avatars and draws people in, but what speficially made you want to install it?

Top 10 Job Interview Questions

July 8. 2010 02:31

Top Interview questions

Well that makes 2 things that I learned today.  This and google now has a ton of greasemonkey scripts which I never knew about.  You learn something every day?  I got more than what I bargained for! hahaha.

Top Interview questions

July 10. 2010 19:13

hypercom t7plus manual

Hi. I just noticed that your site looks like it has a few code problems at the very top of your website's page. Is it an older version of Blog Engine?  I'm not sure if everybody is getting this same bugginess when browsing your site? I am employing a totally different browser than most people, referred to as lynx, so that is what might be causing my problem? I just wanted to make sure you know. Thanks for posting some great postings and I'll try to return back with a completely different browser to check things out!

hypercom t7plus manual

July 16. 2010 08:05

girls piss

Well written blog, well researched and useful for me in the future.I am so happy you took the time and effort to make this. Best of luck

girls piss

July 22. 2010 08:03

tinnitus treatment

I really liked this.

tinnitus treatment

July 27. 2010 02:41

table-magician

I prefer to look on the brighter side of things which I'm sure you can appreciate.

table-magician

July 29. 2010 00:15

Trendspotting

Apple now has Rhapsody as an app, which is a great start, but it is currently hampered by the inability to store locally on your iPod, and has a dismal 64kbps bit rate. If this changes, then it will somewhat negate this advantage for the Zune, but the 10 songs per month will still be a big plus in Zune Pass' favor.

Trendspotting

July 29. 2010 04:49

migraine

Migraine is hoofdpijn die in aanvallen komt. De hoofdpijn komt plotseling op, soms midden in de nacht zodat u er wakker van wordt. De pijn zit meestal aan ...

migraine

July 29. 2010 09:39

Trendspotting

This is getting a bit more subjective, but I much prefer the Zune Marketplace. The interface is colorful, has more flair, and some cool features like 'Mixview' that let you quickly see related albums, songs, or other users related to what you're listening to. Clicking on one of those will center on that item, and another set of "neighbors" will come into view, allowing you to navigate around exploring by similar artists, songs, or users. Speaking of users, the Zune "Social" is also great fun, letting you find others with shared tastes and becoming friends with them. You then can listen to a playlist created based on an amalgamation of what all your friends are listening to, which is also enjoyable. Those concerned with privacy will be relieved to know you can prevent the public from seeing your personal listening habits if you so choose.

Trendspotting

August 1. 2010 01:36

lenen

Lenen Zonder BKR Toetsing Lenen zonder BKR toetsing stijgt in populariteit op het Internet. Veel mensen met een zogeheten BKR notatie, die toch geld willen lenen zijn op zoek naar ...

lenen

August 2. 2010 04:50

akg k404

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon.

akg k404

August 5. 2010 06:02

ray ban

I enjoyed reading your nice blog. I see you offer priceless info. Congratulations, and keep posting to us. Do have some sort of email system where your blog posts emailed to me?

ray ban

August 12. 2010 01:16

hypotheek

Hoeveel kan ik lenen? (hypotheek). Wat worden mijn maandlasten? (hypotheek) ... Hoeveel hypotheek heb ik nodig? Hoe hoog is de boete die ik nu zou moeten

hypotheek

August 26. 2010 11:42

ray ban wayfarer

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

ray ban wayfarer

August 27. 2010 05:36

girls cam

You really know your stuff... Keep up the good work!

girls cam

August 30. 2010 03:05

Smokeless Cigarettes

I truly loved this brilliant article. Please continue this awesome work. Regards, Duyq.

Smokeless Cigarettes

September 1. 2010 02:29

Lemonade Diet Supplement

Thanks for the informative article. Will check out more of your blog posts!

Lemonade Diet Supplement

September 4. 2010 12:24

Gold Coins

I don't usually reply to posts but I will in this case. WoW

Gold Coins

September 5. 2010 05:19

sex cam

You may have not intended to do so, but I think you have managed to express the state of mind that a lot of people are in. The sense of wanting to help, but not knowing how or where, is something a lot of us are going through.

sex cam

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading