1
votes

im trying to bind an observable collection(keyframes) located in the elements of my listbox to my datatemplate's itemssource(observable collection)

<ListBox x:Name="lbTimeLines"  
DataContext="{Binding MainViewport,Source={StaticResource Locator}}" 
ItemsSource="{Binding AnimateableObjects}"  SelectedIndex="{Binding selectedIndex}">
        <ListBox.ItemTemplate >
                        <DataTemplate DataType="{x:Type obj:ObjectSettings }">
                            <cc:TimeLine x:Name="TL" Height="25"  
                                         ItemsSource="{Binding Path=KeyFrames}"<!-- here is the problem -->
                                         CurrentFrame="{Binding LayerView.CurrentFrame,Source={StaticResource Locator},Mode=TwoWay}"   
                                         Width="{Binding LayerView.Globalwidth,Source={StaticResource Locator}}">
                            </cc:TimeLine>
                        </DataTemplate>
       </ListBox.ItemTemplate>

however this seems to result in the error

System.Windows.Data Error: 40 : BindingExpression path error: 'KeyFrames' property not found on 'object' ''TimeLineViewModel' (HashCode=2312607)'. BindingExpression:Path=KeyFrames; DataItem='TimeLineViewModel' (HashCode=2312607); target element is 'TimeLine' (Name='MainControl'); target property is 'ItemsSource' (type 'ObservableCollection`1')

not shure why but he seems to be looking for KeyFrames in the TimeLine's viewmodel instead of the listbox elements

note: i'm using similar binding on a different listbox, this however seems to work fine

<ListBox  x:Name="lbLayers"  
DataContext="{Binding MainViewport,Source={StaticResource Locator}}" 
ItemsSource="{Binding AnimateableObjects}" SelectedIndex="{Binding selectedIndex}">
<ListBox.ItemTemplate>
    <DataTemplate DataType="{x:Type obj:ObjectSettings }">
        <StackPanel >
            <Label Content="{Binding Name}" Height="25" Width="180"></Label>
        </StackPanel>
    </DataTemplate>
</ListBox.ItemTemplate>

1
Nothing wrong there. Your diagnosis may be incorrect. I'd use a tool like Snoop or 2015's UI inspectors to examine the view models and property values of the controls in this part of the tree.user1228
thanks for the response, i have updated my question, the problem seems to have disappeared :/ not shure what caused it in the first placeDrumstig
I'd strongly suggest you remove your edit and add it as an answer below. After the required wait you can mark it as the solution. That's normally what is done in this situation.user1228

1 Answers

0
votes

while i was waiting for an answer i have change my xaml so the keyframe would be bound to a hidden itemscontrol, and my timeline's itemssource was bound to the itemscontrol itemssource

this allowed me to continue working

<ListBox x:Name="lbTimeLines"  DataContext="{Binding MainViewport,Source={StaticResource Locator}}" ItemsSource="{Binding AnimateableObjects}"  SelectedIndex="{Binding selectedIndex}">
<ListBox.ItemTemplate >
    <DataTemplate DataType="{x:Type obj:ObjectSettings }" >
        <StackPanel Orientation="Horizontal">
            <ItemsControl x:Name="Testcontainer" ItemsSource="{Binding KeyFrames, Mode=TwoWay}" Visibility="Hidden" Width="0">
            </ItemsControl>
            <cc:TimeLine Height="25"  
                     ItemsSource="{Binding ElementName=Testcontainer, Path=ItemsSource,Mode=TwoWay}"
                     CurrentFrame="{Binding LayerView.CurrentFrame,Source={StaticResource Locator},Mode=TwoWay}"   
                     Width="{Binding LayerView.Globalwidth,Source={StaticResource Locator}}">
            </cc:TimeLine>
        </StackPanel>
    </DataTemplate>
</ListBox.ItemTemplate>

after the first answer i changed my code back to the original, but i couldn't reproduce the error