How to set Edge color ?

Jun 2, 2012 at 7:29 PM


I need to give each edge a weight and i have to set each edge color depends on it's weight .

I think the best way would be by setting the style of the EdgeControl , but i'm making something wrong . plz help !

Or at least if there is a way to do it by code ..

Like graphLayout.HighLightEdge(myEdge);

but it's not working for me !


Any help will be appreciated


Nov 30, 2012 at 1:29 PM
Edited Dec 17, 2012 at 4:06 PM

If your custom edge has an int Weight property you could use the EdgeControl style to set the edge Foreground by binding to the Weight and using a converter to convert it into a color.


<Setter Property="Foreground" Value="{Binding Path=Weight, Converter={StaticResource MyConverter}}"/>


And then in MyConverter's Convert method:


        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            int weight = value as int;
            if(weight < 10) return new SolidColorBrush(Colors.Blue);
            else if(weight<50) return new SolidColorBrush(Colors.Yellow);
            else if(weight<100) return new SolidColorBrush(Colors.Red);
            // or whatever other colors need to be returned