private MonthViewDayContainer CreateNewContainer()
        {
            var container = new MonthViewDayContainer();

            freeContainers.Add(container);
            NewContainerCreated?.Invoke(this, container);
            return(container);
        }
        private void MonthViewPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            selectionAnchor = null;
            ResetSelection();

            Mouse.Capture(this, CaptureMode.Element);

            // Retrieve the coordinate of the mouse position.
            Point point = e.GetPosition((UIElement)sender);

            selectionAnchor            = GetContaionerAtPoint(point);
            selectionAnchor.IsSelected = true;
        }
        private MonthViewDayContainer GetContaionerAtPoint(Point point)
        {
            MonthViewDayContainer container = null;

            // Perform the hit test against a given portion of the visual object tree.
            HitTestResult result = VisualTreeHelper.HitTest(this, point);

            if (result != null)
            {
                container = result.VisualHit as MonthViewDayContainer;
            }

            return(container);
        }
        public MonthViewDayContainer GetContainer(int dayNumber)
        {
            MonthViewDayContainer container = null;

            // try to find container that is already used to that date
            if (dateToContainerMapping.ContainsKey(dayNumber) == true)
            {
                var candidateContainer = dateToContainerMapping[dayNumber];
                if (freeContainers.Contains(candidateContainer) == true)
                {
                    freeContainers.Remove(candidateContainer);
                    container = candidateContainer;
                }
            }

            // if not found just get container from free containers
            if (container == null && freeContainers.Count > 0)
            {
                container = freeContainers.First();
                freeContainers.Remove(container);
            }

            // if we still we don't have a container, create a new one
            if (container == null)
            {
                container = CreateNewContainer();
                allContainers.Add(container);
            }

            container.Day = dayNumber;

            container.Visibility = System.Windows.Visibility.Visible;

            if (dateToContainerMapping.ContainsKey(dayNumber) == false)
            {
                dateToContainerMapping.Add(dayNumber, container);
            }

            return(container);
        }
        private void MakeSelection(MonthViewDayContainer container)
        {
            bool selectionStarted = false;

            foreach (var day in monthViewDayItems)
            {
                if (day != null)
                {
                    if (selectionAnchor == container)
                    {
                        container.IsSelected = true;
                    }
                    else if (day == container || day == selectionAnchor)
                    {
                        selectionStarted = !selectionStarted;
                    }

                    day.IsSelected = selectionStarted;
                }
            }

            selectionAnchor.IsSelected = true;
            container.IsSelected       = true;
        }
 private void ContainerCache_NewContainerCreated(object sender, MonthViewDayContainer e)
 {
     Children.Add(e);
 }