protected override IEnumerable <IDisposable> Initialize()
        {
            _originalBackground     = Native.Background;
            _originalTitleTextColor = Native.GetTitleTextColor();

            // Content
            // This allows custom Content to be properly laid out inside the native Toolbar.
            _contentContainer = new Border()
            {
                Visibility = Visibility.Collapsed,
                // This container requires a fixed height to be properly laid out by its native parent.
                // According to Google's Material Design Guidelines, the Toolbar must have a minimum height of 48.
                // https://material.io/guidelines/layout/structure.html
                Height = 48,
            };
            _contentContainer.SetParent(Element);
            Native.AddView(_contentContainer);
            yield return(Disposable.Create(() => Native.RemoveView(_contentContainer)));

            yield return(_contentContainer.RegisterParentChangedCallback(this, OnContentContainerParentChanged));

            // Commands.Click
            Native.MenuItemClick += Native_MenuItemClick;
            yield return(Disposable.Create(() => Native.MenuItemClick -= Native_MenuItemClick));

            // NavigationCommand.Click
            Native.NavigationClick += Native_NavigationClick;
            yield return(Disposable.Create(() => Native.NavigationClick -= Native_NavigationClick));

            // Commands
            VectorChangedEventHandler <ICommandBarElement> OnVectorChanged = (s, e) => Invalidate();

            Element.PrimaryCommands.VectorChanged   += OnVectorChanged;
            Element.SecondaryCommands.VectorChanged += OnVectorChanged;
            yield return(Disposable.Create(() => Element.PrimaryCommands.VectorChanged -= OnVectorChanged));

            yield return(Disposable.Create(() => Element.SecondaryCommands.VectorChanged -= OnVectorChanged));

            // Properties
            yield return(Element.RegisterDisposableNestedPropertyChangedCallback(
                             (s, e) => Invalidate(),
                             new[] { CommandBar.PrimaryCommandsProperty },
                             new[] { CommandBar.SecondaryCommandsProperty },
                             new[] { CommandBar.ContentProperty },
                             new[] { CommandBar.ForegroundProperty },
                             new[] { CommandBar.ForegroundProperty, SolidColorBrush.ColorProperty },
                             new[] { CommandBar.ForegroundProperty, SolidColorBrush.OpacityProperty },
                             new[] { CommandBar.BackgroundProperty },
                             new[] { CommandBar.BackgroundProperty, SolidColorBrush.ColorProperty },
                             new[] { CommandBar.BackgroundProperty, SolidColorBrush.OpacityProperty },
                             new[] { CommandBar.VisibilityProperty },
                             new[] { CommandBar.PaddingProperty },
                             new[] { CommandBar.OpacityProperty },
                             new[] { SubtitleProperty },
                             new[] { NavigationCommandProperty },
                             new[] { BackButtonVisibilityProperty },
                             new[] { BackButtonForegroundProperty },
                             new[] { BackButtonIconProperty }
                             ));
        }
        protected override IEnumerable <IDisposable> Initialize()
        {
            _visibilitySubscriptions = new SerialDisposable();
            yield return(_visibilitySubscriptions);

            // Content
            _titleView = new TitleView();
            _titleView.SetParent(Element);
            _titleView.RegisterParentChangedCallback(this, OnTitleViewParentChanged);
            yield return(Disposable.Create(() => _titleView = null));

            // Commands
            VectorChangedEventHandler <ICommandBarElement> OnVectorChanged = (s, e) => RegisterCommandVisibilityAndInvalidate();

            Element.PrimaryCommands.VectorChanged   += OnVectorChanged;
            Element.SecondaryCommands.VectorChanged += OnVectorChanged;
            yield return(Disposable.Create(() => Element.PrimaryCommands.VectorChanged -= OnVectorChanged));

            yield return(Disposable.Create(() => Element.SecondaryCommands.VectorChanged -= OnVectorChanged));

            // Properties
            yield return(Element.RegisterDisposableNestedPropertyChangedCallback(
                             (s, e) => RegisterCommandVisibilityAndInvalidate(),
                             new[] { CommandBar.PrimaryCommandsProperty },
                             new[] { CommandBar.ContentProperty },
                             new[] { NavigationCommandProperty },
                             new[] { NavigationCommandProperty, AppBarButton.VisibilityProperty },
                             new[] { BackButtonTitleProperty }
                             ));

            RegisterCommandVisibilityAndInvalidate();
        }
Example #3
0
        private static void OnEnabledPropertyChanged(DependencyObject dp, DependencyPropertyChangedEventArgs e)
        {
            var element = dp as ListBox;

            if (element == null)
            {
                return;
            }
            var newValue = (bool)e.NewValue;

            var autoScrollWorker = new VectorChangedEventHandler <object>((s1, e2) => ScrollToLastItem(element));

            if (element.Items == null)
            {
                return;
            }

            if (newValue)
            {
                element.Items.VectorChanged += autoScrollWorker;
            }
            else
            {
                element.Items.VectorChanged -= autoScrollWorker;
            }
        }
        /// <summary>
        /// Occurs when the collection changes.
        /// </summary>
        /// <param name="args">Collection changed arguments.</param>
        private void OnCollectionChanged(NotifyCollectionChangedEventArgs args)
        {
            Debug.Assert(args != null, "args cannot be null.");

            NotifyCollectionChangedEventHandler handler = this.CollectionChanged;

            if (handler != null)
            {
                handler(this, args);
            }

            // Also raise VectorChanged using the information passed to us via
            // the CollectionChanged args.
            VectorChangedEventHandler <T> vectorHandler = this.VectorChanged;

            if (vectorHandler != null)
            {
                CollectionChange change;
                uint             index;
                switch (args.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    change = CollectionChange.ItemInserted;
                    index  = (uint)args.NewStartingIndex;
                    break;

                case NotifyCollectionChangedAction.Remove:
                    change = CollectionChange.ItemRemoved;
                    index  = (uint)args.OldStartingIndex;
                    break;

                //case NotifyCollectionChangedAction.Move:   //3 not defined in wp7 NotifyCollectionChangedAction
                case NotifyCollectionChangedAction.Replace:
                    change = CollectionChange.ItemChanged;
                    index  = (uint)args.NewStartingIndex;
                    break;

                case NotifyCollectionChangedAction.Reset:
                default:

                    if (Convert.ToInt32(args.Action) == 3)
                    {
                        //case NotifyCollectionChangedAction.Move
                        change = CollectionChange.ItemChanged;
                        index  = (uint)args.NewStartingIndex;
                        break;
                    }

                    change = CollectionChange.Reset;
                    index  = 0;
                    break;
                }

                vectorHandler(this, new VectorChangedEventArgs(change, index));
            }
        }
Example #5
0
        /// <summary>
        /// This method will be called when the AutoScrollToEnd
        /// property was changed
        /// </summary>
        /// <param name="s">The sender (the ListBox)</param>
        /// <param name="e">Some additional information</param>
        public static void OnAutoScrollToEndChanged(DependencyObject s, DependencyPropertyChangedEventArgs e)
        {
            var listBox      = s as ListBox;
            var listBoxItems = listBox.Items;

            var scrollToEndHandler = new VectorChangedEventHandler <object>(
                (s1, e1) =>
            {
                if (listBox.Items.Count > 0)
                {
                    object lastItem = listBox.Items[listBox.Items.Count - 1];
                    listBox.ScrollIntoView(lastItem);
                }
            });

            if ((bool)e.NewValue)
            {
                listBoxItems.VectorChanged += scrollToEndHandler;
            }
            else
            {
                listBoxItems.VectorChanged -= scrollToEndHandler;
            }
        }
 public static void TryRaiseInserted(this VectorChangedEventHandler <object> handler, IObservableVector <object> owner, uint index)
 => handler?.Invoke(owner, new VectorChangedEventArgs(CollectionChange.ItemInserted, index));
 public static void TryRaiseReseted <T>(this VectorChangedEventHandler <T> handler, IObservableVector <T> owner)
 => handler?.Invoke(owner, new VectorChangedEventArgs(CollectionChange.Reset, 0));
 public static void TryRaiseRemoved <T>(this VectorChangedEventHandler <T> handler, IObservableVector <T> owner, uint index)
 => handler?.Invoke(owner, new VectorChangedEventArgs(CollectionChange.ItemRemoved, index));
Example #9
0
 public HRESULT add_VectorChanged([NativeTypeName("VectorChangedEventHandler<T_logical> *")] VectorChangedEventHandler <T> *handler, [NativeTypeName("EventRegistrationToken *")] EventRegistrationToken *token)
 {
     return(((delegate * unmanaged <IObservableVector <T> *, VectorChangedEventHandler <T> *, EventRegistrationToken *, int>)(lpVtbl[6]))((IObservableVector <T> *)Unsafe.AsPointer(ref this), handler, token));
 }