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. Image for the cookie policy date

SfTreeNavigator binding problem

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.

1 Reply

VR Vijayalakshmi Roopkumar Syncfusion Team June 19, 2017 06:35 AM UTC

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.

Loader.
Up arrow icon