Hello all,
I need a scenario in which the item template of OrgChartNodeLayout(in GlobalNodeLayouts) needs to be different based on some conditions.
For example:
<ig:XamOrgChart.GlobalNodeLayouts> <ig:OrgChartNodeLayout TargetTypeName="Department" DisplayMemberPath="DepartmentName" Key="Departments" /></ig:XamOrgChart.GlobalNodeLayouts>
In above example, suppose if Department has sub-Departments, then, one template should be used.
But if that Department doesn't have Sub-Departments,instead ,has Employees, then other template should be used.
The class structure for Department class is :
public class Department { public Department(string name) { this.DepartmentName =name; this.Departments = new ObservableCollection<Department>(); this.Employees = new ObservableCollection<Employee>(); }
public string DepartmentName { get; set; }
public ObservableCollection<Department> Departments { get; set; } public ObservableCollection<Employee> Employees { get; set; } }
If Department has Sub-Departments, the Departments(Observable collection) will have value [Count > 1] and if it doesn't have Sub-Department, then the Employees will have value [Count > 1].
How can I achieve different Item Template based on above conditions? [For List Box , there is itemTemplateSelector, is there any similar approach in this one? ]
Thank you in advance for your time.
Help..
Hello,
One option to set the item template on the XamOrgChart based on certain conditions is to create some OrgChartNodeLayouts and set the DisplayMemberPath, TargetTypeName, and Key in code-behind.
Then, use an if-else statement to check to see if a certain collection in your datasource has a count greater than 0 and if so, add the corresponding OrgChartNodeLayout to the XamOrgChart.GlobalNodeLayouts collection.
I have attached a sample demonstrating the above.
If the sample I have attached is not sufficient to solve this issue in the way that you had expected, please respond with more information so I can modify it to suit your needs.
Sincerely,AndrewDeveloper Support IInfragistics Inc.www.infragistics.com/support
I have added the desired behavior in the snapshot .please check the attached sanps.
And.
Hello Ram,
I went back and added the SubDepartment class again as I felt it was necessary to achieve the functionality you are looking for. The Department class now only has a name and a collection of SubDepartments, as it acts as the top node of the XamOrgChart. The SubDepartment class now has two collections, with one of Employees and the other of SubDepartments.
In the XAML, I set the SubDepartment ItemTemplate up to include a StackPanel with a TextBlock that displays the name of the SubDepartment and then a ListBox to list the employees if there are any. If there aren’t any, I set up a Converter to toggle the Visibility of the ListBox to collapsed if it’s Items.Count property is 0.
Please let me know if you have any questions or concerns.
HI,
Thanks for the reply.
I haven't tried your solution but I think I have solved the problem (without using SubDepartment).
I 'll try the solution provided by you as well.
What I did was " I kept both two templates content into the one template and among those two, only one is called at a time, so the other one is not called.(Based) on data conditions. "
Thanks,
Ram.
Thanks Andrew,
For now, the problem is solved. So, thanks for all your help and suggestions.
I will let you know if i need any further assist regarding this matter.
For now, it's ok.
Thanks once again.
Regards,
I am glad that you were able to find a solution to this issue. Is there anything else I may be able to assist you with regarding this matter?