Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding with a DataTemplate for System DataType
    text
    copied!<p>This may either be a silly question or i've searched for the wrong words:<br> I have a ComboBox and want to display doubles using a custom converter (showing the equivalent fraction).<br> 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!</p> <p>Adding the System-namespace to the window doesn't compile</p> <pre><code>&lt;Window ... xmlns:sys="clr-namespace:System" ...&gt; </code></pre> <p>Simply typing Double or System.Double in DataType doesn't either.</p> <p>And defining a ViewModel for a simple Double-Type can't be the solution either, can it?!</p> <p>This is my code so far:</p> <pre><code>&lt;ComboBox ItemsSource="{Binding Gains}" SelectedItem="{Binding Gain, Mode=TwoWay}"&gt; &lt;ComboBox.Resources&gt; &lt;DataTemplate DataType=" ??????? fract"&gt; &lt;TextBlock Text="{Binding ., Converter=fractConverter}"/&gt; &lt;/DataTemplate&gt; &lt;/ComboBox.Resources&gt; &lt;/ComboBox&gt; </code></pre> <p><strong>FULL SOLUTION:</strong></p> <p>Using the System namespace as <em>sys:</em> works!<br> <em>Gains</em> is a List&lt;Double&gt;<br> <em>Gain</em> is a Double</p> <pre><code>&lt;Window ... xmlns:sys="clr-namespace:System;assembly=mscorlib" ...&gt; </code></pre> <p>The Combobox works like this:</p> <pre><code>&lt;ComboBox ItemsSource="{Binding Gains}" SelectedItem="{Binding Gain, Mode=TwoWay}"&gt; &lt;ComboBox.Resources&gt; &lt;DataTemplate DataType="{x:Type sys:Double}"&gt; &lt;TextBlock Text="{Binding ., Converter={StaticResource realConverter}}"/&gt; &lt;/DataTemplate&gt; &lt;/ComboBox.Resources&gt; &lt;/ComboBox&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload