Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UWP Treeview IsSelected and IsExpanded #48

Open
johnmurphy01 opened this issue Jun 15, 2017 · 5 comments
Open

UWP Treeview IsSelected and IsExpanded #48

johnmurphy01 opened this issue Jun 15, 2017 · 5 comments

Comments

@johnmurphy01
Copy link

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!

@xyzzer
Copy link
Owner

xyzzer commented Jun 15, 2017

Seems like you should start by debugging the TreeViewItem code to see what is null and then figure out why. If you're currently using NuGet I would try to grab the sources instead and include them in your solution. It makes debugging easier.

@johnmurphy01
Copy link
Author

image

Here are the inspection results from TreeItemView.cs in method CheckForSelectedDescendents line 700. The properties IsExpanded and IsSelected are null from the TreeItemView. My data context looks correct and the values of open and selected are populated. Is there some additional configuration that has to happen in order to use IsExpanded and IsSelected? If I removed the modifications I made to the Style, everything is okay. Here's the structure of my data:

public class TreeChildren: INotifyPropertyChanged
	{
		public int nodeId { get; set; }
		public string name { get; set; }
		public int nodeDetailTypeId { get; set; }
		public int nodeTypeId { get; set; }
		public int treeId { get; set; }
		public int parent { get; set; }
		public int rank { get; set; }
		public bool isDeleted { get; set; }
		public int MaxDepth { get; set; }
		public string namePath { get; set; }
		public bool open { get; set; }
		public List<TreeChildren> children { get; set; }
		public bool selected { get; set; }

		public FontAwesome.UWP.FontAwesomeIcon icon
		{
			get
			{
				if (open)
				{
					return FontAwesome.UWP.FontAwesomeIcon.FolderOutlinepenOutline;
				}
				return FontAwesome.UWP.FontAwesomeIcon.FolderOutline;
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;

		public void OnPropertyChanged(string name)
		{
			PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
		}
	}

And I'm just setting the ItemsSource of the treeview to my data.

@xyzzer
Copy link
Owner

xyzzer commented Jun 19, 2017

Again, you should look at the source of the toolkit and at the details of the exception stack. The problem is more than likely in the toolkit code and you'd need to fix the toolkit to address your problem.

@surensaluka
Copy link

Hi,
Can someone guide me how programmatically expand and collapse the tree and subtrees?
My app also a UWP and I currently do not use a property called IsExpand.

@xyzzer
Copy link
Owner

xyzzer commented Mar 14, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants