Please take a look at the attached example of hierarchical datasoure bound to xamDiagram.
I want to change the background of nodes based on employee type enum value, say if its admin employee background to take a colour and if academic staff then node should take different colour.
I tried using datatriggers but could not achieve it. Please help.
Hello Abs,
Thank you for your post.
Unfortunately, I was unable to see the sample project that you had attached, as it appears that the file may have corrupted, and so I am unable to extract or view the contents of your attached .zip file.
I do have a couple of recommendations on this matter, though. While I can't really see what your DataTrigger looks like, I would recommend that you write a Style for DiagramNode in this case. Binding your DataTrigger to the data context of that node will not help on this matter, though, as the data context of the nodes in the XamDiagram share the same data context as the diagram itself. Instead, each of these nodes have a Content property which should represent the underlying item of that particular node. So, if you were to bind to the following in your DataTrigger, you should be able to check the enum value and set the background property of your nodes:
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Content.EnumPropertyName}" Value="someValue" >
I hope this helps. Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
My style is inline with your suggestion but it does not work.
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Employee.EmployeType}" Value="Admin">
<Style TargetType="{x:Type ig:DiagramNode}" x:Key="EmpNode" BasedOn="{StaticResource {x:Type ig:DiagramNode}}"> <Setter Property="Fill" Value="CadetBlue">Setter> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Employee.EmployeType}" Value="Admin"> <Setter Property="Fill" Value="Crimson">Setter> DataTrigger> Style.Triggers> Style>
I have re attached the zip file, please can you retry?