Data binding to enumeration collections
We've already seen a number of examples of data binding to enumeration instances. We've seen converters that we can use to convert our enumeration values and Extension methods that we can use to extract additional information from each member. Earlier in this chapter, we even saw a full but basic example using our BitRate
enumeration. Now, with our new-found knowledge, let's see how we can improve that earlier example.
As noted, in the previous example, we manually declared a RadioButton
control for each of our enumerations. While that is fine for our three member enumeration, it wouldn't make so much sense to use this method if we had a large number of members. Instead, let's think about how we could use a DataTemplate
to declare how each member should be rendered. Let's remind ourselves how we declared each RadioButton
in the previous example.
<RadioButton Content="16 bits" IsChecked="{Binding BitRate, Converter={StaticResource EnumToBoolConverter...