Changing Vertex color of a single node

Jun 25, 2010 at 10:07 AM

Do anyone have any idea how to change the vertex color of a single node?

The node original color is Grey. I manage to change the color using Highlightvertex to red. When mouse over, it will change to blue. After mouse over, the color return back to Grey. Is it possible to keep that node remain red color after the mouse over?

 

Dec 10, 2010 at 6:17 AM

hi,

i wanna create colored graph and each node has a special color, but i dont know how?

please help me!

tnx

Developer
Dec 14, 2010 at 10:46 AM

Hi guys, thank you for your interest in Grapfh# control.

Please, do not ask a question on another question. Would be better open two separate topic.

@windz82

To achive your goal, you can use a DataTrigger that set the background color of your vertex after mouse over. Take a look at following code:

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

           <Border x:Name="vertexBorder">

               <StackPanel ToolTip="{Binding Path=Description}" x:Name="vertexPanel">

                   <TextBlock />

               </StackPanel>

           </Border>

          <DataTemplate.Triggers>

               <DataTrigger Binding="{Binding Path=IsSelected}" Value="True">

                   <Setter TargetName="vertexBorder" Property="BorderBrush" Value="Black"></Setter>

               </DataTrigger>

           </DataTemplate.Triggers>

       </DataTemplate>

In this example, I set a DataTemplate for my vertex (EntityVertex in my domain) with a DataTrigger that set the border to black where a user select a vertex. When the user click on a vertex i set True the IsSelected property that fires the datatrigger which set the borderbrush property. . You can easily follow this example.

@homeshahab

Of course is possible, for example you can define a property that will discriminate the color of you vertex, and with datatrigger set the color based on its value. Look at the previous example, you can set color based on id (for example)

 

               <DataTrigger Binding="{Binding Path=Id}" Value="1">

                   <Setter TargetName="vertexBorder" Property="Backgroundcolor" Value="Black"></Setter>

               </DataTrigger>

               <DataTrigger Binding="{Binding Path= Id }" Value="2">

                   <Setter TargetName="vertexBorder" Property=" Backgroundcolor " Value="White"></Setter>

               </DataTrigger>

 

               <DataTrigger Binding="{Binding Path= Id }" Value="3">

                   <Setter TargetName="vertexBorder" Property=" Backgroundcolor " Value="Orange"></Setter>

               </DataTrigger>

This is the way.

 

I bet you have a lot of vertices and several color to set. You can do it programmatically to make dynamic the color association. If you need more help, please contact me.

 

Enjoy coding!

 

badagn

 

Dec 14, 2010 at 4:10 PM

hi

i'm sorry i thought questions are the same.

i open "graph coloring problem". please check it

http://graphsharp.codeplex.com/Thread/View.aspx?ThreadId=237834

Dec 14, 2010 at 4:47 PM

Hi guys

i need coloring   graph vertex , i should do it dynaically becaese i need it t show graph coloring problem answer. please explain more because it is my first program in WPf.

please step by step i'm new....

tnx

Coordinator
Dec 15, 2010 at 8:29 AM

Hi homeshahab!

If WPF is new for you, then you should start learning WPF (datatemplates, triggers, XAML, ...) - and ask those questions on a WPF forum. If you have those basic skills in WPF, you will solve these dynamic-graph-coloring problem in a super easy and fast way.

So what you need to do, ask those questions (or google them) on a WPF-specific forum:

  • wpf datatemplates/controltemplates? how do they work?
  • Datatriggers?
  • converters?

Sorry if I don't provide you a specific answer (but I provided you the way you get your answer). I think you should learn these things to use Graph# properly.

Dec 19, 2010 at 7:52 AM

hi

i read about the titles, what should i do now?

plz help me, i dont have enough time

Jan 29, 2012 at 10:35 AM

Hi Guys,

I have a question to this solution:

In case of a property of my new class MSVertex I want to change the color (background and border) of a Vertex. 

Therefor I wrote this code:

<DataTemplate DataType="{x:Type Sample:MSVertex}">
        <DataTemplate.Triggers>
        	<DataTrigger Binding="{Binding Path=Status}" Value="1">
                    <Setter TargetName="vertexBorder" Property="Backgroundcolor" Value="blue"></Setter>
                </DataTrigger>
	</DataTemplate.Triggers>
</DataTemplate>

Now if I try to run the code, I get the Error: Cannot find the Trigger.Destination "vertexBorder"

So how can I define the TargetName or which is the right target name?

Can anyone help me? 

Coordinator
Jan 29, 2012 at 10:46 AM
Edited Jan 29, 2012 at 10:51 AM

 

I think you're missing the actual DataTemplate in this code:

<DataTemplate DataType="{x:Type Sample:MSVertex}">
        <DataTemplate.Triggers>
        	<DataTrigger Binding="{Binding Path=Status}" Value="1">
                    <Setter TargetName="vertexBorder" Property="Backgroundcolor" Value="blue"></Setter>
                </DataTrigger>
	</DataTemplate.Triggers>
</DataTemplate>
See badang's example (it's the 5th message above your one), the releveant part (you're missing the emphasised border part):

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

           <Border x:Name="vertexBorder">

               <StackPanel ToolTip="{Binding Path=Description}x:Name="vertexPanel">

                   <TextBlock />

               </StackPanel>

           </Border>

          <DataTemplate.Triggers>

               <DataTrigger Binding="{Binding Path=IsSelected}Value="True">

                   <Setter TargetName="vertexBorderProperty="BorderBrushValue="Black"></Setter>

               </DataTrigger>

           </DataTemplate.Triggers>

       </DataTemplate>

 

ps: @labberlich: Your problem has nothing to do with Graph#. If WPF is new for you, then you should start learning WPF (datatemplates, triggers, XAML, ...) - and ask those questions on a WPF forum.