AlternationConverter
AlternationConverter は IValueConverter の一実装で、リストボックスや表を縞々にするのによく使われますが、数→オブジェクト汎用のコンバータなので実はいろいろ便利です。
<AlternationConverter x:Key="IconConverter"> <BitmapImage UriSource="Resources\hoge.png" CreateOptions="DelayCreation" /> <BitmapImage UriSource="Resources\foo.png" CreateOptions="DelayCreation" /> <BitmapImage UriSource="Resources\bar.png" CreateOptions="DelayCreation" /> </AlternationConverter> <Image Name="image" Width="16" Margin="2,1" Source="{Binding Path=ImageIndex, Converter={StaticResource IconConverter}}" />
こうすると数から画像に変換できます。単純な配列から値を引くだけのコンバータを書かなくても済みます。