private DateTimeAutomationPeer GetOrCreateDateTimeAutomationPeer(DateTime date, CalendarMode buttonMode, bool addParentInfo)
        {
            DateTimeCalendarModePair dateTimeCalendarModePair = new DateTimeCalendarModePair(date, buttonMode);
            DateTimeAutomationPeer   dateTimeAutomationPeer   = null;

            this.DateTimePeers.TryGetValue(dateTimeCalendarModePair, out dateTimeAutomationPeer);
            if (dateTimeAutomationPeer == null)
            {
                dateTimeAutomationPeer = this.GetPeerFromWeakRefStorage(dateTimeCalendarModePair);
                if (dateTimeAutomationPeer != null && !addParentInfo)
                {
                    dateTimeAutomationPeer.AncestorsInvalid = false;
                    dateTimeAutomationPeer.ChildrenValid    = false;
                }
            }
            if (dateTimeAutomationPeer == null)
            {
                dateTimeAutomationPeer = new DateTimeAutomationPeer(date, this.OwningCalendar, buttonMode);
                if (addParentInfo && dateTimeAutomationPeer != null)
                {
                    dateTimeAutomationPeer.TrySetParentInfo(this);
                }
            }
            AutomationPeer wrapperPeer = dateTimeAutomationPeer.WrapperPeer;

            if (wrapperPeer != null)
            {
                wrapperPeer.EventsSource = dateTimeAutomationPeer;
            }
            return(dateTimeAutomationPeer);
        }
Example #2
0
        private DateTimeAutomationPeer GetOrCreateDateTimeAutomationPeer(DateTime date, CalendarMode buttonMode, bool addParentInfo)
        {
            // try to reuse old peer if it exists either in Current AT or in WeakRefStorage of Peers being sent to Client
            DateTimeCalendarModePair key  = new DateTimeCalendarModePair(date, buttonMode);
            DateTimeAutomationPeer   peer = null;

            DateTimePeers.TryGetValue(key, out peer);

            if (peer == null)
            {
                peer = GetPeerFromWeakRefStorage(key);
                if (peer != null && !addParentInfo)
                {
                    // As cached peer is getting used it must be invalidated. addParentInfo check ensures that call is coming from GetChildrenCore
                    peer.AncestorsInvalid = false;
                    peer.ChildrenValid    = false;
                }
            }

            if (peer == null)
            {
                peer = new DateTimeAutomationPeer(date, OwningCalendar, buttonMode);

                // Sets hwnd and parent info
                if (addParentInfo)
                {
                    if (peer != null)
                    {
                        peer.TrySetParentInfo(this);
                    }
                }
            }
            // Set EventsSource if visual exists
            AutomationPeer wrapperPeer = peer.WrapperPeer;

            if (wrapperPeer != null)
            {
                wrapperPeer.EventsSource = peer;
            }

            return(peer);
        }
        private DateTimeAutomationPeer GetOrCreateDateTimeAutomationPeer(DateTime date, CalendarMode buttonMode, bool addParentInfo)
        {
            // try to reuse old peer if it exists either in Current AT or in WeakRefStorage of Peers being sent to Client
            DateTimeCalendarModePair key = new DateTimeCalendarModePair(date, buttonMode); 
            DateTimeAutomationPeer peer = null;
            DateTimePeers.TryGetValue(key, out peer); 
 
            if (peer == null)
            { 
                peer = GetPeerFromWeakRefStorage(key);
                if (peer != null && !addParentInfo)
                {
                    // As cached peer is getting used it must be invalidated. addParentInfo check ensures that call is coming from GetChildrenCore 
                    peer.AncestorsInvalid = false;
                    peer.ChildrenValid = false; 
                } 
            }
 
            if( peer == null )
            {
                peer = new DateTimeAutomationPeer(date, OwningCalendar, buttonMode);
 
                // Sets hwnd and parent info
                if (addParentInfo) 
                { 
                    if(peer != null)
                        peer.TrySetParentInfo(this); 
                }
            }
            // Set EventsSource if visual exists
            AutomationPeer wrapperPeer = peer.WrapperPeer; 
            if (wrapperPeer != null)
            { 
                wrapperPeer.EventsSource = peer; 
            }
 
            return peer;
        }