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

Dificulties on Binding Data From DataSource to Nodes

Hello,

I'm trying to bind the information from datasource to diagram at XAML, but I wasn't able to accomplish it. I put below the XAML used as the code used.
I really would appreciate it if someone could point out what I'm doing wrong.

XAML:
<syncfusion:SfDiagram x:Name="diagram">
            <syncfusion:SfDiagram.NodeTemplate>
                <DataTemplate>
                    <Grid WidthRequest="80" HeightRequest="80" BindingContext="this">
                        <Label Text="{Binding name}" BackgroundColor="Red" TextColor="Green"/>
                    </Grid>
                </DataTemplate>
            </syncfusion:SfDiagram.NodeTemplate>
        </syncfusion:SfDiagram>

Code:
            employees = new ObservableCollection<Employee>();
            employees.Add(new Employee() { name = "Elizabeth", id = 1, parentId = 0, designation = "CEO" });
            employees.Add(new Employee() { name = "Christina", id = 2, parentId = 1, designation = "Manager" });
            employees.Add(new Employee() { name = "Yang", id = 3, parentId = 1, designation = "Manager" });

            diagram.DataSourceSettings = new DataSourceSettings()
            {
                DataSource = employees,
                Id = "id",
                ParentId = "parentId"
            };

            DirectedTreeLayout treeLayout = new DirectedTreeLayout()
            {
                HorizontalSpacing = 80,
                VerticalSpacing = 80,
                TreeOrientation = TreeOrientation.TopToBottom
            };

            diagram.LayoutManager = new LayoutManager()
            {
                Layout = treeLayout
            };

1 Reply

DS Devaraj Sekar Syncfusion Team January 2, 2020 07:15 AM UTC

Hi customer, 
 
Thank you for contacting Syncfusion support. 
 
The data template binding for node while implementing “Layout” in SfDiagram should be carried out in code level. The data binding from xaml level for layout will not reflect in node since, it is the behavior of SfDiagram. We have prepared a sample based on the provided details, which can be downloaded from the below link. 
 
 
Kindly let us know if you require any further assistance. 
 
Regards, 
Devaraj S 


Loader.
Live Chat Icon For mobile
Up arrow icon