예제 #1
0
        private TimeLineItemControl CreateTimeLineItemControl(ITimeLineDataItem data)
        {
            Binding startBinding = new Binding("StartTime");
            startBinding.Mode = BindingMode.TwoWay;
            startBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            Binding endBinding = new Binding("EndTime");
            endBinding.Mode = BindingMode.TwoWay;
            endBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            DateTime timelineStart = StartDate;

            Binding expandedBinding = new Binding("TimelineViewExpanded");
            expandedBinding.Mode = BindingMode.TwoWay;
            endBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;

            TimeLineItemControl adder = new TimeLineItemControl();
            adder.TimeLineStartTime = timelineStart;
            adder.DataContext = data;
            adder.Content = data;

            adder.SetBinding(TimeLineItemControl.StartTimeProperty, startBinding);
            adder.SetBinding(TimeLineItemControl.EndTimeProperty, endBinding);
            adder.SetBinding(TimeLineItemControl.IsExpandedProperty, expandedBinding);

            if (_template != null)
            {
                adder.ContentTemplate = _template;
            }

            /*adder.PreviewMouseLeftButtonDown += item_PreviewEditButtonDown;
            adder.MouseMove += item_MouseMove;
            adder.PreviewMouseLeftButtonUp += item_PreviewEditButtonUp;*/
            adder.PreviewMouseRightButtonDown += item_PreviewEditButtonDown;
            adder.MouseMove += item_MouseMove;
            adder.PreviewMouseRightButtonUp += item_PreviewEditButtonUp;

            adder.PreviewMouseLeftButtonUp += item_PreviewDragButtonUp;
            adder.PreviewMouseLeftButtonDown += item_PreviewDragButtonDown;
            adder.UnitSize = UnitSize;
            return adder;
        }
예제 #2
0
        private void ScrollToItem(ITimeLineDataItem target)
        {
            Double tgtNewWidth = 0;
            Double maxUnitSize = 450;//28000;
            Double minUnitSize = 1;
            if (_scrollViewer != null)
            {
                for (int i = 1; i < Children.Count; i++)
                {
                    var ctrl = Children[i] as TimeLineItemControl;
                    if (ctrl != null && ctrl.DataContext == target)
                    {
                        Double curW = ctrl.Width;
                        if (curW < 5)
                        {
                            tgtNewWidth = 50;
                        }
                        else if (curW > _scrollViewer.ViewportWidth)
                        {
                            tgtNewWidth = _scrollViewer.ViewportWidth / 3;
                        }

                        if (tgtNewWidth != 0)
                        {
                            Double newUnitSize = (UnitSize * tgtNewWidth) / curW;
                            if (newUnitSize > maxUnitSize)
                                newUnitSize = maxUnitSize;
                            else if (newUnitSize < minUnitSize)
                                newUnitSize = minUnitSize;
                            UnitSize = newUnitSize;
                            SynchronizeSiblings();
                        }
                        ctrl.BringIntoView();
                        return;
                    }
                }
            }
        }