Skip to content

UWP Treeview IsSelected and IsExpanded #48

@johnmurphy01

Description

@johnmurphy01

I am attempting to override the style of the treeview and the treeview items. I have copied the styles from
https://github.com/xyzzer/WinRTXamlToolkit/blob/master/WinRTXamlToolkit/Controls/TreeView/TreeViewItem.xaml
and
https://github.com/xyzzer/WinRTXamlToolkit/blob/master/WinRTXamlToolkit/Controls/TreeView/TreeView.xaml

I added FontAwesome folder icons to control the expand collapse and removed the arrow toggle symbol. I added a couple of Setters for IsSelected and IsExpanded that are bound to two properties on my object that is part of the data source. However, when I run the application, I'm getting a null reference exception:

   at WinRTXamlToolkit.Controls.TreeViewItem.get_IsSelected()
   at WinRTXamlToolkit.Controls.TreeView.CheckForSelectedDescendents(TreeViewItem item)
   at WinRTXamlToolkit.Controls.TreeViewItem.set_ParentItemsControl(ItemsControl value)
   at WinRTXamlToolkit.Controls.TreeView.PrepareContainerForItemOverride(DependencyObject element, Object item)
   at Windows.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)

Here are the changes I made to the style. If I remove these the tree is rendered but I have no way of controlling expansion or selection:

<Style
        TargetType="controls:TreeViewItem">
			<Setter 
			Property="IsExpanded"
            Value="{Binding open, Mode=TwoWay}" />
			<Setter 
			Property="IsSelected"
            Value="{Binding selected, Mode=TwoWay}" />

This worked in WPF but I'm trying to create a UWP application from my existing source code and was not using the Toolkit prior to UWP. Please help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions