This may either be a silly question or i’ve searched for the wrong words:
I have a ComboBox and want to display doubles using a custom converter (showing the equivalent fraction).
In the DataTemplate i have to specify a DataType, which is Double, but i don’t know how to specity it. I’m sure there is a simple way to do so!
Adding the System-namespace to the window doesn’t compile
<Window ... xmlns:sys="clr-namespace:System" ...>
Simply typing Double or System.Double in DataType doesn’t either.
And defining a ViewModel for a simple Double-Type can’t be the solution either, can it?!
This is my code so far:
<ComboBox ItemsSource="{Binding Gains}" SelectedItem="{Binding Gain, Mode=TwoWay}">
<ComboBox.Resources>
<DataTemplate DataType=" ??????? fract">
<TextBlock Text="{Binding ., Converter=fractConverter}"/>
</DataTemplate>
</ComboBox.Resources>
</ComboBox>
FULL SOLUTION:
Using the System namespace as sys: works!
Gains is a List<Double>
Gain is a Double
<Window ... xmlns:sys="clr-namespace:System;assembly=mscorlib" ...>
The Combobox works like this:
<ComboBox ItemsSource="{Binding Gains}" SelectedItem="{Binding Gain, Mode=TwoWay}">
<ComboBox.Resources>
<DataTemplate DataType="{x:Type sys:Double}">
<TextBlock Text="{Binding ., Converter={StaticResource realConverter}}"/>
</DataTemplate>
</ComboBox.Resources>
</ComboBox>
Like this: