views:

1251

answers:

2

Hi

I am building an application to display a datagrid bound to an ObservableCollection of Records, where each record has a Course Object and an ObservableCollection of Results Objects.

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

It works great on loading, but subsequent updates to the course selection via the autocomplete does not trigger a recalculation/refresh of the value converter.

Is there a way to trigger the refresh in XAML. I added UpdateSource=Property changed to the binding of the list box - 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 box and reset a filter that I already have on the datagrid. But isn;t this very inefficient ? Refreshing the view on the datagrid does not have any effect in that method.

Any steps in the right direction are greatly appreciated. Trying to prevent myself going anymore grey :)

Had thoughts of getting the binding expression of the list in the grid and updating it, but no clue ?

Thanks guys

+1  A: 

First ensure that the Record object implements INotifyPropertyChanged and the Course property invokes it.

Does the converter in resultToBrushConverter require access to more than one property of the bound object? If it depends only on Course than use Course as its path.

Edit:

Assuming you do have these things in place your binding on Fill should look like:-

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

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

AnthonyWJones
Thanks for the response. The Record object does implement the InotifyPropertyChanged and Course does invoke it (breakpoint verified).The converter is used on the bound collection of Results. Internal to the converter - the code picks up the Coarse and colours the circles in accordingly. Somehow I need the change of Course to update/trigger the binding so that the converter is triggered and creates new colours accordingly. (A break point in the converter verifies it is never called after the initial load). Something to the effect of Course triggers Record Binding update...
LJ
A: 

Did you ever fix this?

I'm in a similar situation :(

Matthew Black