0

I am trying to bind to a TreeView with ReactiveUI in WPF, but nothing is being displayed. Can anyone tell me where I am going wrong, or give me some advice on how to debug it?

Binding in View constructor:

            this.OneWayBind(ViewModel,
                vm => vm.NonTableItemCommentsViewModels,
                view => view.CommentTree.ItemsSource);

Xaml:

    <TreeView Name="CommentTree" ItemsSource="{Binding}">
        <TreeView.Resources>
            <!-- Template for Items -->
            <HierarchicalDataTemplate  DataType="{x:Type viewModels:NonTableItemCommentsViewModel}"
                                      ItemsSource="{Binding Path=Comments, Mode=OneWay}">
                <TextBlock Text="{Binding Path=ItemId, Mode=OneWay}" />
            </HierarchicalDataTemplate>
            <!-- Template for Comments -->
            <DataTemplate  DataType="{x:Type viewModels:CommentViewModel}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Path=Text, Mode=OneWay}"
                               Margin="3,0" />
                    <TextBlock Text="{Binding Path=Author, Mode=OneWay}"
                               Margin="3,0" />
                </StackPanel>
            </DataTemplate>
        </TreeView.Resources>
    </TreeView>

Items and Comments are both ObservableCollections.

Peter Dongan
  • 1,762
  • 12
  • 17
  • Are you getting items at all? – Andy Feb 01 '23 at 14:46
  • What do your viewmodels look like? – Andy Feb 01 '23 at 14:46
  • Both votes to close are on the basis of "needs debugging details" which means the voters think you need to supply more info. – Andy Feb 01 '23 at 14:47
  • The view models are being populated without issue. When I try a simple binding of the number of items to a label, that is displayed as expected as well. However I found what I expect to be a solution: https://stackoverflow.com/questions/35371598/how-to-use-reactiveui-with-a-hierarchical-data-source-tree-view – Peter Dongan Feb 01 '23 at 14:53
  • 1
    See where he sets the itemssource here: https://github.com/condron/ReactiveUI-TreeView/blob/master/TreeViewInheritedItem/MainWindow.xaml.cs – Andy Feb 01 '23 at 14:59
  • Great. That's exactly what the problem was. Thanks. – Peter Dongan Feb 01 '23 at 15:33

0 Answers0