internal void RaiseAutomationFocusEvent(DateTime currentDate)
        {
            CalendarSelectableCellnfoAutomationPeer infoPeer = this.GetOrCreatePeerFromDateTime(currentDate);

            if (infoPeer != null)
            {
                infoPeer.RaiseAutomationEvent(AutomationEvents.AutomationFocusChanged);
            }
        }
        /// <summary>
        /// Gets the provider of the peer for given row and column indices.
        /// </summary>
        /// <param name="row">The index of the peer's row.</param>
        /// <param name="column">The index of the peer's column</param>
        /// <returns></returns>
        public IRawElementProviderSimple GetItem(int row, int column)
        {
            CalendarSelectableCellnfoAutomationPeer peer = this.childrenCache.OfType <CalendarSelectableCellnfoAutomationPeer>()
                                                           .Where(x => (x.CellModel.RowIndex == row && x.CellModel.ColumnIndex == column)).FirstOrDefault();

            if (peer != null)
            {
                return(this.ProviderFromPeer(peer));
            }

            return(null);
        }
        private CalendarSelectableCellnfoAutomationPeer GetOrCreatePeerFromDateTime(DateTime date)
        {
            CalendarSelectableCellnfoAutomationPeer peer = this.childrenCache.OfType <CalendarSelectableCellnfoAutomationPeer>().Where(x => x.CellModel.Date == date).FirstOrDefault();

            if (peer == null && this.CalendarOwner.Model.CalendarCells != null)
            {
                CalendarCellModel model = this.CalendarOwner.Model.CalendarCells.Where(cell => cell.Date == date).FirstOrDefault();
                if (model != null)
                {
                    CalendarViewHostAutomationPeer hostPeer = (CalendarViewHostAutomationPeer)FrameworkElementAutomationPeer.FromElement(this.CalendarOwner.calendarViewHost);
                    peer = new CalendarSelectableCellnfoAutomationPeer(hostPeer, model);
                    this.childrenCache.Add(peer);
                }
            }
            return(peer);
        }
        internal void RaiseSelectionEvents(CurrentSelectionChangedEventArgs args)
        {
            if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected))
            {
                CalendarSelectableCellnfoAutomationPeer peer = GetOrCreatePeerFromDateTime(args.NewSelection);
                if (peer != null)
                {
                    peer.RaiseAutomationEvent(AutomationEvents.AutomationFocusChanged);
                    peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected);
                }
            }

            if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection))
            {
                CalendarSelectableCellnfoAutomationPeer peer = GetOrCreatePeerFromDateTime(args.NewSelection);
                if (peer != null)
                {
                    peer.RaiseAutomationEvent(AutomationEvents.AutomationFocusChanged);
                    peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection);
                }
            }
        }