Binding to ObservableCollection

Jul 6, 2009 at 10:19 AM

Hi all,

I am trying (and failing!) to perform what should be a relatively simple binding from an ObservableCollection to the text property of a DataGridTextColumn's ElementStyle.

Note, however, that I am not trying to bind to the SelectedItem, but rather to bind the entire collection. The reason I am doing this is as part of a multibinding; the ValueConverter compares data for the SelectedItem to data throughout the rest of the collection in order to produce a result.

I have seen several examples on the MSDN forums that suggest the principle is sound, but I cannot appear to get the binding right - when I look at the values in my MultiConverter, the ObservableCollections (there are two) are either set to DependencyProperty.UnsetValue or strings matching the names of the ObservableCollections. I can successfully bind the ObservableCollections to a DataGrid's ItemsSource, whilst the "SplitTimes[0]" object is (a member of the objects held in the ObservableCollection) binds successfully, which I think means my DataContext is okay.

Here is my binding:

        <Style x:Key="dataGridSplitColumnElementStyle" TargetType="TextBlock" BasedOn="{x:Static dataGrid:DataGridTextColumn.DefaultElementStyle}">
            <Setter Property="Text">
                    <MultiBinding Converter="{StaticResource splitTimeValueConverter}">
                        <Binding Path="SplitTimes[0]"/>
                        <Binding Source="MainSessionData" Path="."/>
                        <Binding Source="SummarySessionData" Path="."/>

Any help greatly appreciated.