EventColor

May 29, 2012 at 12:37 PM

Hey

your timeline controle is very cool. so i used it! but on times i have a problem. you used for the TimeLineEvent.EventColor a string. So  i must used the system colors like Blue or LightBlue. Is there an way to use Hexcode like #ff33ee?

 

Thanks 

 

Daniel

Coordinator
May 30, 2012 at 3:45 PM

You can change TimelineDisplayEvent class to provide this functionality.

Jul 26, 2012 at 10:23 AM

Hi Fanfon.

I've been working on this also for color changes. You can use this methods. You pass in a hex color as a string, and it retuirns a Color objecr instance.

   public static Color FromHex(string hex)
        {
            string v = hex.TrimStart('#');
            if (v.Length > 8) //replace with number 8
                return Colors.Blue;
            if (v.Length == 6)
                v = "FF" + v; // Add Alpha value
            if (v.Length < 6) //replace with number 6
                v = "FF" + v;
            while (v.Length < 8) //replace with number 8
                v += "0";
            Color c = new Color();
            c.A = (byte)System.Convert.ToInt32(v.Substring(0, 2), 16);
            c.R = (byte)System.Convert.ToInt32(v.Substring(2, 2), 16);
            c.G = (byte)System.Convert.ToInt32(v.Substring(4, 2), 16);
            c.B = (byte)System.Convert.ToInt32(v.Substring(6, 2), 16);
            return c;
        }
Dec 13, 2012 at 11:46 AM
Edited Dec 13, 2012 at 2:07 PM

Just thought I'd add to this discussion as I've found a solution to a similar problem of my own.

I've overridden the DataTemplate TimelineEventStyle in Styles.xaml, replacing the "Fill" attribute so it looks like this

                <Rectangle x:Name="EventDurationRect"
                           ...(other stuff)...
                           Width="{Binding EventPixelWidth, Mode=OneWay}">
                    <!--Fill="{Binding EventColorBrush, Mode=OneWay}" replaced as below -->
                    <Rectangle.Fill>
                        <SolidColorBrush  Color="{Binding Event.EventColor}" />
                    </Rectangle.Fill>

This now works with all Windows.Media.Color values, not just the 16 static ones, and you may also define your "color" property as "#FF33EE" etc as well and it will work.

That's the only change necessary, no code changes/additions needed, and it seems the EventColorBrush property is no longer needed either (except where I haven't overridden it in other templates).

Hope this helps

Ade.