ValueConverter and the mapping domain quandary

  • RSS
  • Add To My MSN
  • Add To Windows Live
  • Add To My Yahoo
  • Add To Google

Statistics

  • Entries (148)
  • Comments (0)
09 Oct 2011 Categories: domain Silverlight 4 ValueConverter wp7 WPF
Rate this Content 0 Votes

ValueConverter seems like just the ticket for handling data types whose domains are finite sets of named values (think enum). But how do you get the domain definition into scope? Resource dictionaries are wonderful until you find they’re out of scope. And they’re always out of scope for the code of a ValueConverter. You can’t pass them in as ConverterParameter because it isn’t a DependencyProperty.

What you can do is use a MultiBinding and a MultiConverter, and pass the resource as one of the binding values. This rather good trick also works for DynamicResource, so you can declaratively marshal into scope a completely arbitrary value that doesn’t even exist till run-time.

Unless indicated otherwise, all blog entries for On Second Thought are original works by Peter Wone

Comments

Comments are closed on this post.
Site Map | Printable View | © 2008 - 2013 PD Consulting and Security | Powered by mojoPortal | HTML 5 | CSS | Design by mitchinson