Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The second way to load images is to load them globally using the Images property. This property loads the images such that they are accessible to all items. Instead of having each item maintain its own image in memory, you instruct each item to point to one of the global images. The Images property allows you to load any number of images and to assign them unique names, or keys. Then, instead of setting an item's ItemImage property to a path and filename, you set the property to the key of a global image. This saves us a lot of memory, but it is still tedious to implement without some sort of automation.

...

More often than not, images are used for classification. Therefore, the ItemClass property can be very useful in automating images. Using our previous example, imagine a tree that contains the structure of an email inbox. When you add items to a tree, you can specify the item's class. For emails, you can set the class to "Mail". In order to show email icons next to these items, you simply load the global images and set the condition like so:

...

The first section of code loads two global images, MailIcon and FolderIcon. Now, we could just as easily set each item's ItemImage property to one of these two icons, but it's a lot easier to use the ImageConditions property instead. So, we set two conditions. The first condition says that the MailIcon should be used if the item's class is equal to Mail. The second condition says to always use the FolderIcon. The list is processed sequentially, like a Case statement, such that the first true condition is the one whose image is used. Thus, we could envision the conditions used in our example to read like the following pseudo-code case statement:

...

You can enhance the look and feel of the SRP Tree Control using the ImageEffects property. Just like the ImageConditions property, the ImageEffects property is a series of Conditions. When a condition evaluates to true, then the associated special effect is applied to the item's image. Use this if you want to add hover effects or emphasize selected items.

See Also

ImagesImageConditionsImageEffectsItemImage