Note that there are some explanatory texts on larger screens.

plurals
  1. POInvoke IValueConverter's ConvertBack on load
    text
    copied!<p>I bind combobox (that is a part if listbox item template) to enum, the selected item is bound to the collection that is bound to listbox. <br/> I use a converter for some logic. </p> <p>The problem is that the ConvertBack is not invoked on startup, but only when I re-select the item in combobox.</p> <p>I need it to invoke also on start. </p> <pre><code>public enum FullEnum { Apple, Banana, Pear } </code></pre> <pre class="lang-xml prettyprint-override"><code>&lt;Window.Resources&gt; &lt;local:EnumConverter x:Key="enumConverter"/&gt; &lt;ObjectDataProvider x:Key="DataT" MethodName="GetValues" ObjectType="{x:Type sys:Enum}"&gt; &lt;ObjectDataProvider.MethodParameters&gt; &lt;x:Type TypeName="local:FullEnum" /&gt; &lt;/ObjectDataProvider.MethodParameters&gt; &lt;/ObjectDataProvider&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="190*" /&gt; &lt;RowDefinition Height="71*" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;ListBox Name="list1" Margin="0,0,0,37"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding Path=Label}"&gt;&lt;/TextBlock&gt; &lt;ComboBox Height="23" Width="90" ItemsSource="{Binding Source={StaticResource DataT}}" SelectedValue="{Binding Path=Oped, Converter={StaticResource enumConverter}}"&gt; &lt;/ComboBox&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; &lt;/Grid&gt; </code></pre> <pre class="lang-cs prettyprint-override"><code>List&lt;Item1&gt; list = new List&lt;Item1&gt;(); public Window1() { InitializeComponent(); list.Add(new Item1 { Label="label1" }); list.Add(new Item1 { Label = "label2" }); list.Add(new Item1 { Label = "label3" }); list1.ItemsSource = list; } public class Item1 { public FullEnum Oped { get; set; } public string Label { get; set; } } public class EnumConverterr : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { //some code } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ((int)value != 0) return (EnumSuperior)value; return (EnumSuperior)7; } } </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