We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

SfTreeNavigator binding problem

Thread ID:

Created:

Updated:

Platform:

Replies:

131022 Jun 16,2017 10:19 AM Jun 19,2017 02:35 AM WPF 1
loading
Tags: SfTreeNavigator
Sasha Zuev
Asked On June 16, 2017 10:19 AM

Hello guys. I have problem with SfTreeNavigator. Binding not working, not working even the example from the documentation. My code:
Xaml
        <syncfusion:SfTreeNavigator Header=" Controllers" ItemsSource="{Binding Nodes}" Margin="10,10,560,10">
            <syncfusion:SfTreeNavigator.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Nodes}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Name}" Foreground="Green" FontWeight="Bold" VerticalAlignment="Center" Margin="18 0 0 0"/>
                    </StackPanel>
                </HierarchicalDataTemplate>
            </syncfusion:SfTreeNavigator.ItemTemplate>
        </syncfusion:SfTreeNavigator>
Main form
        List<TreeNode> Controllers
        {
            get
            {
                List<TreeNode> nodes = new List<TreeNode>();
                foreach (CPolicyData cpd in aipolicy.Controllers)
                {
                    ObservableCollection<TreeNode> node = new ObservableCollection<TreeNode>();
                    foreach (CTriggerData ctd in cpd.Triggers)
                    {
                        node.Add(new TreeNode() { Name = $"[{ctd.ID}] {ctd.Name}" });
                    }
                    nodes.Add(new TreeNode() { Name = $"{cpd.ID}", Nodes = node });
                }
                return nodes;
            }
            set => Controllers = value;
        }
Tree node class
    public class TreeNode : NotificationObject
    {
        private string name { get; set; }
        public string Name
        {
            get { return name; }
            set
            {
                name = value;
            }
        }
        private ObservableCollection<TreeNode> nodes { get; set; }
        public ObservableCollection<TreeNode> Nodes
        {
            get { return nodes; }
            set { nodes = value; }
        }

        public TreeNode()
        {
            Nodes = new ObservableCollection<TreeNode>();
        }
    }
After programm starting control is empty.

Vijayalakshmi Roopkumar [Syncfusion]
Replied On June 19, 2017 02:35 AM

Hi Sasha

Thank you for contacting Syncfusion Support.

We have analyzed your problem and found that you have missed to set the DataContext in your application. DataContext is the main source of binding, so SfTreeNavigator control is not displayed in Window. We have prepared the sample for the same. Please refer the code example and sample from the following link: 
Code Example: [C#] 
 
public MainWindow() 
{ 
InitializeComponent(); 
this.DataContext = new TreeViewModel(); 
} 
 
 
 
 
Code Example: [XAML] 
 
<navigation:ChromelessWindow.DataContext> 
<local:TreeViewModel></local:TreeViewModel> 
</navigation:ChromelessWindow.DataContext> 
 
 
 
 Screenshot: 
  
Kindly check with above solution and let us know if it is helpful.

Regards
Vijayalakshmi V.R.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;