コード例 #1
0
        void VisualizeItemsSource()
        {
            //make sure we have all the values needed, before attempting to visualize
            if (_TimeLineEnd != null && _TimeLineStart != null && _ItemsSource != null)
            {
                //Width of the event: (event-length / timeline-length) * width of root canvas
                double w = (_ItemsSource.End - _ItemsSource.Start).TotalDays / (_TimeLineEnd.Value - _TimeLineStart.Value).TotalDays * RootCanvas.ActualWidth;
                TimeLineBorder.Width  = (w > 0) ? w : 0;
                TimeLineBorder.Height = (RootCanvas.ActualHeight > 3) ? RootCanvas.ActualHeight - 3 : RootCanvas.ActualHeight;
                RootCanvas.Background = _ItemsSource.BackGround;
                Canvas.SetTop(TimeLineBorder, 1.5);
                //place where event starts in the timeline: (event-start - timeline-start)/(timeline-end - event-start) * width of root canvas
                double borderLeft = (_ItemsSource.Start - _TimeLineStart.Value).TotalDays / (_TimeLineEnd.Value - _TimeLineStart.Value).TotalDays * RootCanvas.ActualWidth;
                Canvas.SetLeft(TimeLineBorder, borderLeft);

                //line at bottom of timeline, to separate it from next one.
                Canvas.SetTop(BottomBorderLine, RootCanvas.ActualHeight - 0.1);
                BottomBorderLine.X2 = RootCanvas.ActualWidth;

                //write out the label and tooltip
                TimeLineTextBlock.Text = _ItemsSource.Label;
                Canvas.SetTop(TimeLineTextBlock, 2);
                double textBlockLeft = borderLeft + 4;
                if (textBlockLeft < 0)
                {
                    textBlockLeft = 2;
                }
                Canvas.SetLeft(TimeLineTextBlock, textBlockLeft);
                textBlockLeft = borderLeft + 5;
                if (textBlockLeft < 0)
                {
                    textBlockLeft = 3;
                }
                ToolTipService.SetToolTip(TimeLineBorder, _ItemsSource.ToolTip);
                ToolTipService.SetToolTip(TimeLineTextBlock, _ItemsSource.ToolTip);
                RootCanvas.UpdateLayout();
            }
        }