Vertex ItemTemplate

Jun 29, 2009 at 8:06 AM
Edited Jun 29, 2009 at 10:21 AM

Hi there,

 

I'm really liking Graph# so far! Quick question:

How does one override the behavior of having each Vertex on a Graph, so that it doesn't display the ToString() of the object the Vertex represents, but instead uses an ItemTemplate to define the appearance of each Vertex?

 

Thanks! And thanks for Graph#!

Coordinator
Jun 29, 2009 at 10:39 AM
Edited Jun 29, 2009 at 10:39 AM

You can use DataTemplates for example:

 

<Window ...
xmlns:myns="clr-namespace:NamespaceOfYourVertexType[OPTIONALLY needed this: ;assembly=assembly_name_which_contains_your_vertex_class_if_its_not_the_same_as_your_window's_assemlby_(without_dll_postfix)]">
<Window.Resources>
<!-- define with a datatemplate how to show your vertex class-->
<DataTemplate DataType="{x:Type myns:YourVertexType}">
<!-- here goes my vertex representation -->
</DataTemplate>
</Window.Resources>

<!-- here is the GraphLayout Control -->
</Window>

 

 

Developer
Jul 1, 2009 at 8:36 AM

this is on of my implementation:

 

 

        <DataTemplate DataType="{x:Type common_graph:EntityVertex}">

            <Border Name="vertexPanel"

                    Margin="3"

                    Padding="4"

                    CornerRadius="5, 5, 5, 5"

                    BorderThickness="2"

                    BorderBrush="LightGray"

                    >

                <StackPanel ToolTip="{Binding Path=Description}">

                    <TextBlock Text="{Binding Path=Code, FallbackValue=VertexId}" TextAlignment="Center"/>                

                </StackPanel>

            </Border>

            <DataTemplate.Triggers>

                <DataTrigger Binding="{Binding Path=EntityType.Name}" Value="Factory">

                    <Setter  TargetName="vertexPanel" Property="Background" Value="LightBlue"/>

                </DataTrigger>

                <DataTrigger Binding="{Binding Path=EntityType.Name}" Value="Department">

                    <Setter  TargetName="vertexPanel" Property="Background" Value="LightGreen"/>

                </DataTrigger>

                <DataTrigger Binding="{Binding Path=EntityType.Name}" Value="ProductionLine">

                    <Setter  TargetName="vertexPanel" Property="Background" Value="LightYellow"/>

                </DataTrigger>

                <DataTrigger Binding="{Binding Path=EntityType.Name}" Value="Workcenter">

                    <Setter  TargetName="vertexPanel" Property="Background" Value="Yellow"/>

                </DataTrigger>

                <DataTrigger Binding="{Binding Path=EntityType.Name}" Value="Workstation">

                    <Setter  TargetName="vertexPanel" Property="Background" Value="WhiteSmoke"/>

                </DataTrigger>

                <DataTrigger Binding="{Binding Path=EntityType.Name}" Value="ProductionMachine">

                    <Setter  TargetName="vertexPanel" Property="Background" Value="NavajoWhite"/>

                </DataTrigger>

            </DataTemplate.Triggers>

        </DataTemplate>