Beispiel #1
0
        private static void OnViewChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ListView listView = (ListView)d;

            ViewBase oldView = (ViewBase)e.OldValue;
            ViewBase newView = (ViewBase)e.NewValue;

            if (newView != null)
            {
                if (newView.IsUsed)
                {
                    throw new InvalidOperationException(SR.Get(SRID.ListView_ViewCannotBeShared));
                }
                newView.IsUsed = true;
            }

            // In ApplyNewView ListView.ClearContainerForItemOverride will be called for each item.
            // Should use old view to do clear item.
            listView._previousView = oldView;
            listView.ApplyNewView();
            // After ApplyNewView, if item is removed, ListView.ClearContainerForItemOverride will be called.
            // Then should use new view to do clear item.
            listView._previousView = newView;

            //Switch ViewAutomationPeer in ListViewAutomationPeer
            ListViewAutomationPeer lvPeer = UIElementAutomationPeer.FromElement(listView) as ListViewAutomationPeer;

            if (lvPeer != null)
            {
                if (lvPeer.ViewAutomationPeer != null)
                {
                    lvPeer.ViewAutomationPeer.ViewDetached();
                }

                if (newView != null)
                {
                    lvPeer.ViewAutomationPeer = newView.GetAutomationPeer(listView);
                }
                else
                {
                    lvPeer.ViewAutomationPeer = null;
                }
                //Invalidate the ListView automation tree because the view has been changed
                lvPeer.InvalidatePeer();
            }

            if (oldView != null)
            {
                oldView.IsUsed = false;
            }
        }
        // Token: 0x06005168 RID: 20840 RVA: 0x0016D250 File Offset: 0x0016B450
        private static void OnViewChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ListView listView  = (ListView)d;
            ViewBase viewBase  = (ViewBase)e.OldValue;
            ViewBase viewBase2 = (ViewBase)e.NewValue;

            if (viewBase2 != null)
            {
                if (viewBase2.IsUsed)
                {
                    throw new InvalidOperationException(SR.Get("ListView_ViewCannotBeShared"));
                }
                viewBase2.IsUsed = true;
            }
            listView._previousView = viewBase;
            listView.ApplyNewView();
            listView._previousView = viewBase2;
            ListViewAutomationPeer listViewAutomationPeer = UIElementAutomationPeer.FromElement(listView) as ListViewAutomationPeer;

            if (listViewAutomationPeer != null)
            {
                if (listViewAutomationPeer.ViewAutomationPeer != null)
                {
                    listViewAutomationPeer.ViewAutomationPeer.ViewDetached();
                }
                if (viewBase2 != null)
                {
                    listViewAutomationPeer.ViewAutomationPeer = viewBase2.GetAutomationPeer(listView);
                }
                else
                {
                    listViewAutomationPeer.ViewAutomationPeer = null;
                }
                listViewAutomationPeer.InvalidatePeer();
            }
            if (viewBase != null)
            {
                viewBase.IsUsed = false;
            }
        }