Search
Tuesday, May 21, 2013 ..:: Blendblog.net ::.. Register  Login
 Bloggers Minimize

  
 Sponsors Minimize

 Print   
 Users Online Minimize
Membership Membership:
Latest New User Latest: gyrofan
New Today New Today: 0
New Yesterday New Yesterday: 0
User Count Overall: 46

People Online People Online:
Visitors Visitors: 5
Members Members: 0
Total Total: 5

Online Now Online Now:

  
 Welcome to blendblog.net! Minimize

If you are a developer or designer who is creating cutting edge user interface experiences using Microsoft Expression Blend you've just found a great resource!  The purpose of this site is to share our experience with this brand new product.  As with any new piece of software there is a ton to discover.  Bugs will be revealed and workarounds discovered, hopefully this can be a resource to share in the discovery process!

While this site will focus largely on Expression Blend, it will also encompass WPF, Visual Studio, Silverlight, and other .net 3.5 technologies as they relate to the creation of great software.

Please login using your Microsoft LiveID or register a new account.  Doing so will let you comment on any of the blog entries on the site.  We look forward to helping you in your endeavors as well as you helping others in theirs!  We'd love to have more bloggers on our site...if you are interested please register and contact us!

Follow us:


  
 Bug in DataTemplateSelector makes it impossible to retrieve template of object in code. Minimize
Location: BlogsSean Cullinan    
Posted by: Sean Cullinan 3/4/2010 12:18 PM

We found a nasty bug today in WPF involving the use of a datatemplate selector.

Here is the jist of it in an example.

If you have a listbox and specify a datatemplate for it directly you can then retrieve that datatemplate in the code behind by simply saying Listbox1.ItemTemplate.  This gives you your item template which you can then traverse to customize elements in that template in your code behind which is a pretty common thing to do.

However, if you are using a DataTemplateSelector to choose the template for an object (we'll continue to use a listbox as an example) you will see that even though visually the template has been applied, in the code behind when you try to retrieve the item template by utilizing Listbox1.ItemTemplate you get a value of "Nothing."

We had a very complex WPF scenario and we assumed that the fact that we were getting nothing returned to us was due to some error in our thinking or logic.  After many hours we were able to determine that the problem was with WPF and this inconsistency.

Attached is a very simple sample application that display's the issue in a very clear fashion.

Please note that I found this article which has a workaround that can be dangerous to use.  The article specifies adding a property to your DataTemplateSelector that stores the last template selected.  This can be very dangerous as if another control calls this DataTemplateSelector the value returned will not be what you expect.

Hopefully this will be fixed in .net 4.0.  In the meantime I will post this on the MS Connect site to see if they can come up with a resolution.  Learning WPF can be very difficult, when it doesn't behave in a stable fashion it becomes very frustrating.

Sean

VB.net sample project illustrating template selector bug.

Permalink |  Trackback

Your name:
Title:
Comment:
Add Comment   Cancel 

  
 Search Minimize

  
 Archive Minimize

  
 Blendblog Survey Minimize
Our next client application will be written using:




Which Tablet Do you expect to buy?





Submit Survey  View Results

 Print   
Copyright 2011 by blendblog.net   Terms Of Use  Privacy Statement
DotNetNuke® is copyright 2002-2013 by DotNetNuke Corporation