示例#1
0
        protected AppBarConductor(IConductActiveItem conductor, PhoneApplicationPage page)
        {
            _conductor = conductor;
            _page      = page;

            _pivot    = _page.GetVisualDescendants().OfType <Pivot>().FirstOrDefault();
            _panorama = _page.GetVisualDescendants().OfType <Panorama>().FirstOrDefault();

            if (_pivot == null && _panorama == null)
            {
                throw new ArgumentException("The appbar conductor must have a Pivot or Panorama to sync with.");
            }

            if (_pivot != null)
            {
                _pivot.LoadedPivotItem += PivotOnLoadedPivotItem;
            }

            if (_panorama != null)
            {
                _panorama.SelectionChanged += PanoramaOnSelectionChanged;

                // Load first appbar in Panorama after animations are complete
                var firstViewAware = conductor.ActiveItem as IViewAware;

                if (firstViewAware != null)
                {
                    EventHandler <ViewAttachedEventArgs> attachedHandler = null;

                    attachedHandler = (sender, args) =>
                    {
                        SyncAppBar(args.View as DependencyObject);

                        firstViewAware.ViewAttached -= attachedHandler;
                    };

                    firstViewAware.ViewAttached += attachedHandler;
                }
            }

            HandleDeferLoad();
        }