Skip to main content

ObservableCollections and the Data Factory

  • Chapter
Foundation Expression Blend 2
  • 213 Accesses

Abstract

What this chapter covers:

  • How to import resources such as images into a WPF application

  • Understanding the Abstract factory pattern, a common design pattern

  • How to use an Abstract factory pattern to create an ObservableCollection of image

  • How to use an ObservableCollection to create a DataSource

  • Using a DataSource to populate a ComboBox

  • Creating a Data Template that describes to WPF how to display the content of a ComboBox as an Image control and a TextBlock control

  • Using an ImageBrush to set the background of a StackPanel in the Workspace to the SelectedItem of your ComboBox

An ObservableCollection is a collection of data that can be watched so that when the collection changes, when items are added or removed, for example, controls bound to that data are updated automatically. In this chapter, I am going to show you how to create an ObservableCollection of images, or rather the path on the hard drive of where the images are located. You will then make use of that ObservableCollection to populate a ComboBox that will have a DataTemplate that tells the ComboBox to show the image and the path of the image. In order to create an ObservableCollection, you are going to make use of a common design pattern called an Abstract factory pattern. A design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern is not code, per se, but rather a template for how to design code to solve problems with many different solutions. Object-oriented design patterns most often show relationships and interactions between classes and objects. Later in this chapter, you are going to create an Abstract factory pattern called an ImageFactory. With that, let’s get started.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 29.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 39.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Rights and permissions

Reprints and permissions

Copyright information

© 2008 Victor Gaudioso

About this chapter

Cite this chapter

(2008). ObservableCollections and the Data Factory. In: Foundation Expression Blend 2. Apress. https://doi.org/10.1007/978-1-4302-0612-5_9

Download citation

Publish with us

Policies and ethics