Ejemplo n.º 1
0
        private void DrawPointEvents(Canvas canvas, double yPos, NonOverlappintEvents <string, string> events)
        {
            var canvasWidth = canvas.ActualWidth;

            var timeLineLength = canvasWidth - FingerWidthInUnits;

            var timeLineStart = HalfFingerWidthInUnits;

            foreach (var @event in events)
            {
                var eventXPos = ((@event.Start - _timeRange.Start) / _timeRange.Duration) * timeLineLength;

                var circle = new Ellipse();

                circle.Width  = 20;
                circle.Height = 20;

                circle.SetValue(Canvas.LeftProperty, timeLineStart + eventXPos - circle.Width / 2);
                circle.SetValue(Canvas.TopProperty, yPos + 1);

                circle.Fill   = Brushes.Black;
                circle.Stroke = Brushes.Black;

                MouseButtonEventHandler mouseDownHandler = (sender, e) =>
                {
                    MessageBox.Show(@event.Description);
                    e.Handled = true;
                };
                circle.MouseDown += mouseDownHandler;
                _releases.AddLast(() => { circle.MouseDown -= mouseDownHandler; });

                canvas.Children.Add(circle);
            }
        }
Ejemplo n.º 2
0
        private void DrawIntervalEvents(
            Canvas canvas,
            double yPos,
            NonOverlappintEvents <string, string> events,
            Color baseColor)
        {
            var canvasWidth = canvas.ActualWidth;

            var timeLineLength = canvasWidth - FingerWidthInUnits;

            var timeLineStart = HalfFingerWidthInUnits;

            foreach (var @event in events)
            {
                var eventStartXPos = timeLineStart + ((@event.Start - _timeRange.Start) / _timeRange.Duration) * timeLineLength;
                var eventEndXPos   = timeLineStart + ((@event.End - _timeRange.Start) / _timeRange.Duration) * timeLineLength;

                var noLeftSide  = @event.Start < _timeRange.Start;
                var noRightSide = @event.End > _timeRange.End;

                var rectangle = new Border();

                rectangle.Width = noLeftSide && noRightSide
                    ? timeLineLength
                    : noLeftSide
                        ? (eventEndXPos - timeLineStart)
                        : noRightSide
                            ? (timeLineLength + timeLineStart - eventStartXPos)
                            : (eventEndXPos - eventStartXPos);
                rectangle.Height = FingerWidthInUnits - 2;

                rectangle.SetValue(
                    Canvas.LeftProperty,
                    noLeftSide ? timeLineStart : eventStartXPos
                    );
                rectangle.SetValue(Canvas.TopProperty, yPos + 1);

                rectangle.BorderBrush     = Brushes.Black;
                rectangle.BorderThickness = new Thickness(
                    noLeftSide ? 0 : 1,
                    1,
                    noRightSide ? 0 : 1,
                    1
                    );
                rectangle.Background = new SolidColorBrush(baseColor);

                canvas.Children.Add(rectangle);

                var text = new TextBlock();
                text.Text  = @event.Description;
                text.Width = rectangle.Width - 2;
                // text.Height = rectangle.Height - 2;
                text.VerticalAlignment = VerticalAlignment.Center;
                text.SetValue(Canvas.LeftProperty, eventStartXPos + 1);
                text.SetValue(Canvas.TopProperty, yPos + 1 + 1);
                text.TextAlignment = TextAlignment.Center;
                text.FontWeight    = FontWeights.Bold;

                MouseButtonEventHandler mouseDownHander = (sender, e) =>
                {
                    MessageBox.Show(@event.Description);
                    e.Handled = true;
                };
                text.MouseDown += mouseDownHander;
                _releases.AddLast(() => { text.MouseDown -= mouseDownHander; });

                rectangle.Child = text;
            }
        }