Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding IValueConverter breaks updates when changed occur from observable collection to UI
    text
    copied!<p>I have a itemscontrol with the item template set to a border, then i bind the datacontext of the listview to a list of objects that contain a bool property.</p> <p>Then i added a click event handler to the border, and when detecting a click, i cast the datacontext of the border to the class and set the bool field to true.</p> <p>That works as a charm, but i want the rectangle to have a specific colour when the bool field is set to true or false, so i created a IValueConverter that takes my class and returns a colour. That works too, the rectangles are different colors based on the bool field.</p> <p>I am still able to click the rectangles, but they just arent updated. The color of the rectangle wont change.</p> <p>Datatemplate from the itemscontrol itemtemplate</p> <pre><code> &lt;DataTemplate&gt; &lt;Border ToolTip="{Binding Seat.Column}" Width="25" Height="25" Margin="0,0,2,2" BorderBrush="Black" Background="{Binding Converter={StaticResource ResourceKey=SeatStateConverter}}" BorderThickness="2" Name="rectangle1" VerticalAlignment="Center" HorizontalAlignment="Center" MouseLeftButtonDown="rectangle1_MouseLeftButtonDown"&gt; &lt;Label Content="{Binding Occupied}" Foreground="White" FontSize="7"&gt;&lt;/Label&gt; &lt;/Border&gt; &lt;/DataTemplate&gt; </code></pre> <p>The click event</p> <pre><code> private void rectangle1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Border item = sender as Border; SeatState state = item.DataContext as SeatState; state.Locked = !state.Locked; } </code></pre> <p>my converter</p> <pre><code> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { SeatState state = value as SeatState; if (state == null) return null; SolidColorBrush brush = new SolidColorBrush(); if (state.Occupied) { brush.Color = Color.FromRgb(172, 0,0); } else if (state.Locked) { brush.Color = Color.FromRgb(214, 65, 0); } else if(!state.Occupied) { brush.Color = Color.FromRgb(0, 172, 0); } return brush; } </code></pre> <p>This works great.. untill i add the converter that converts the objects into a SolidColorBrush.</p> <p>I tried all sorts of crazy stuff that should have nothing to do with my problem.</p> <ul> <li>implementing the convertback method in the IValueConverter interface</li> <li>setting the binding to a two way binding</li> <li>invoking the UpdateLayout method on the ItemsControl</li> </ul> <p>But nothing seemed to work.</p> <p>Anyone got any ideas? My english could be better so please ask if there is anything you want clearified =)</p> <p>Thanks in advance.</p>
 

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