Updating Silverlight / Trigger IValueConverter in Listbox DataTemplate in DataGrid

I am creating an application to display a data binding bound to ObservableCollection Records, where each record has a course object and an ObservableCollection of result objects.

The course is changed using the autocomplete block. The collection of results is displayed in a Listbox with an IValueConverter implementation to change the color of the ellipse template based on the criteria of the selected course.

It works fine on load, but subsequent updates to the course selection using autocomplete does not cause the value converter to be recalculated / updated.

Is there a way to trigger the update in XAML. I added UpdateSource = Property changed to listbox binding but this caused a stack overflow (haha).

Here is the code:

<data:DataGrid x:Name="MyDatGrid">
<data:DataGrid.Columns>
    <data:DataGridTemplateColumn Header="Results">
        <data:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
           <ListBox ItemsSource="{Binding ListOfResults}">
               <ListBox.ItemsPanel>
                   <ItemsPanelTemplate>
                       <StackPanel Orientation="Horizontal"/>
                   </ItemsPanelTemplate>
               </ListBox.ItemsPanel>
               <ListBox.ItemTemplate>
                   <DataTemplate>
                       <Ellipse Width="20" Height="20" Fill="{Binding Converter={StaticResource resultToBrushConverter} }" Stroke="Black" StrokeThickness="1" />
                   </DataTemplate>
               </ListBox.ItemTemplate>
          </ListBox>
        </DataTemplate>
        </data:DataGridTemplateColumn.CellTemplate>
     </data:DataGridTemplateColumn>
     <data:DataGridTemplateColumn Header="Course" >
        <data:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
               <Border>
                   <input:AutoCompleteBox ItemsSource="{Binding Courses, Source={StaticResource coursesSource}}"/>
               </Border>
             </DataTemplate>
     </data:DataGridTemplateColumn.CellTemplate>

      

I managed to subscribe to the LostFocus event on the autocomplete field and reset the filter I already have in the datagrid. But is it ineffective? Updating the view on the datagrid has no effect in this method.

Any steps in the right direction are greatly appreciated. Trying to prevent myself from being more gray :)

Have you thought about getting the list anchor expression in the grid and updating it, but no clue?

Thanks guys,

+2


source to share


1 answer


First, make sure the Record object implements INotifyPropertyChanged and the Course property calls it.

Does the converter to resultToBrushConverter need access to more than one property of the associated object? If it only depends on the course than use it Course

as a path.

Edit



Assuming you have these things, your Fill binding should look like this: -

<Ellipse Width="20" Height="20" Fill="{Binding Coarse, Converter={StaticResource resultToBrushConverter} }" Stroke="Black" StrokeThickness="1" />

      

Now that the binding knows its control over the Coarse property, it should update the Fill when the PropertyChanged event fires for the Coarse property.

+1


source







All Articles