Beispiel #1
0
 private static void AdornedElementChanged(PerspexPropertyChangedEventArgs e)
 {
     var adorner = (Visual)e.Sender;
     var adorned = (Visual)e.NewValue;
     var layer = adorner.GetVisualParent<AdornerLayer>();
     layer?.UpdateAdornedElement(adorner, adorned);
 }
Beispiel #2
0
        /// <summary>
        /// Caled when the <see cref="Items"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void ItemsChanged(PerspexPropertyChangedEventArgs e)
        {
            var incc = e.OldValue as INotifyCollectionChanged;

            if (incc != null)
            {
                incc.CollectionChanged += ItemsCollectionChanged;
            }

            var newValue = e.NewValue as IEnumerable;

            if (newValue == null || newValue.Count() == 0)
            {
                Classes.Add(":empty");
            }
            else
            {
                Classes.Remove(":empty");
            }

            incc = newValue as INotifyCollectionChanged;

            if (incc != null)
            {
                incc.CollectionChanged += ItemsCollectionChanged;
            }
        }
Beispiel #3
0
 /// <summary>
 /// Called when the <see cref="SelectedIndex"/> property changes.
 /// </summary>
 /// <param name="e">The event args.</param>
 private void SelectedIndexChanged(PerspexPropertyChangedEventArgs e)
 {
     if (Panel != null)
     {
         var task = MoveToPage((int)e.OldValue, (int)e.NewValue);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Handle when dependency property value changes to update the underline HtmlContainer with the new value.
 /// </summary>
 private static void OnPerspexProperty_valueChanged(PerspexObject PerspexObject, PerspexPropertyChangedEventArgs e)
 {
     var control = PerspexObject as HtmlLabel;
     if (control != null)
     {
         if (e.Property == AutoSizeProperty)
         {
             if ((bool)e.NewValue)
             {
                 PerspexObject.SetValue(AutoSizeHeightOnlyProperty, false);
                 control.InvalidateMeasure();
                 control.InvalidateVisual();
             }
         }
         else if (e.Property == AutoSizeHeightOnlyProperty)
         {
             if ((bool)e.NewValue)
             {
                 PerspexObject.SetValue(AutoSizeProperty, false);
                 control.InvalidateMeasure();
                 control.InvalidateVisual();
             }
         }
     }
 }
 public void OnEvent(object sender, PerspexPropertyChangedEventArgs e)
 {
     if (e.Property == _property)
     {
         _changed.OnNext(e.NewValue);
     }
 }
Beispiel #6
0
        /// <summary>
        /// Calls <see cref="Layoutable.InvalidateArrange"/> on the parent of the control whose
        /// property changed, if that parent is a canvas.
        /// </summary>
        /// <param name="e">The event args.</param>
        private static void AffectsCanvasArrangeInvalidate(PerspexPropertyChangedEventArgs e)
        {
            var control = e.Sender as IControl;
            var canvas  = control?.Parent as Canvas;

            canvas?.InvalidateArrange();
        }
Beispiel #7
0
        private void SelectedItemChanged(PerspexPropertyChangedEventArgs e)
        {
            var control = e.NewValue as IControl;

            if (control != null)
            {
                control.Measure(Size.Infinity);

                SelectionBoxItem = new Rectangle
                {
                    Width  = control.DesiredSize.Width,
                    Height = control.DesiredSize.Height,
                    Fill   = new VisualBrush
                    {
                        Visual     = control,
                        Stretch    = Stretch.None,
                        AlignmentX = AlignmentX.Left,
                    }
                };
            }
            else
            {
                SelectionBoxItem = e.NewValue;
            }
        }
Beispiel #8
0
        /// <summary>
        /// Called when the <see cref="Items"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private void ItemsChanged(PerspexPropertyChangedEventArgs e)
        {
            if (_createdPanel)
            {
                var generator = ItemContainerGenerator;

                if (e.OldValue != null)
                {
                    generator.Clear();
                    Panel.Children.Clear();

                    INotifyCollectionChanged incc = e.OldValue as INotifyCollectionChanged;

                    if (incc != null)
                    {
                        incc.CollectionChanged -= ItemsCollectionChanged;
                    }
                }

                if (Panel != null)
                {
                    CreateItemsAndListenForChanges((IEnumerable)e.NewValue);
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Called when the <see cref="SelectedIndex"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private async void SelectedIndexChanged(PerspexPropertyChangedEventArgs e)
        {
            if (Panel != null)
            {
                if (_currentTransition == null)
                {
                    int fromIndex = (int)e.OldValue;
                    int toIndex   = (int)e.NewValue;

                    for (;;)
                    {
                        _currentTransition = MoveToPage(fromIndex, toIndex);
                        await _currentTransition;

                        if (_queuedTransitionIndex != -1)
                        {
                            fromIndex = toIndex;
                            toIndex   = _queuedTransitionIndex;
                            _queuedTransitionIndex = -1;
                        }
                        else
                        {
                            _currentTransition = null;
                            break;
                        }
                    }
                }
                else
                {
                    _queuedTransitionIndex = (int)e.NewValue;
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Called when the <see cref="SelectingItemsControl.SelectedIndex"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private void SelectedItemChanged(PerspexPropertyChangedEventArgs e)
        {
            var item    = e.NewValue as IContentControl;
            var content = item?.Content ?? item;

            SelectedTab = item as TabItem;
        }
Beispiel #11
0
        /// <summary>
        /// Called when the <see cref="SelectedIndex"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private void SelectedIndexChanged(PerspexPropertyChangedEventArgs e)
        {
            var index = (int)e.OldValue;

            if (index != -1)
            {
                var container = ItemContainerGenerator.ContainerFromIndex(index);
                MarkContainerSelected(container, false);
            }

            index = (int)e.NewValue;

            if (index == -1)
            {
                SelectedItem = null;
            }
            else
            {
                SelectedItem = Items.Cast <object>().ElementAt((int)e.NewValue);
                var container = ItemContainerGenerator.ContainerFromIndex(index);
                MarkContainerSelected(container, true);

                var inputElement = container as IInputElement;
                if (inputElement != null && Presenter != null && Presenter.Panel != null)
                {
                    KeyboardNavigation.SetTabOnceActiveElement(
                        (InputElement)Presenter.Panel,
                        inputElement);
                }
            }
        }
Beispiel #12
0
 private void ValueChanged(PerspexPropertyChangedEventArgs e)
 {
     if (this.indicator != null)
     {
         double percent = this.Maximum == this.Minimum ? 1.0 : ((double)e.NewValue - this.Minimum) / (this.Maximum - this.Minimum);
         this.indicator.Width = this.Bounds.Width * percent;
     }
 }
Beispiel #13
0
 private void ValueChanged(PerspexPropertyChangedEventArgs e)
 {
     if (_indicator != null)
     {
         double percent = Maximum == Minimum ? 1.0 : ((double)e.NewValue - Minimum) / (Maximum - Minimum);
         _indicator.Width = Bounds.Width * percent;
     }
 }
Beispiel #14
0
 private void ValueChanged(PerspexPropertyChangedEventArgs e)
 {
     if (_indicator != null)
     {
         double percent = Maximum == Minimum ? 1.0 : ((double)e.NewValue - Minimum) / (Maximum - Minimum);
         _indicator.Width = Bounds.Width * percent;
     }
 }
Beispiel #15
0
        private static void AdornedElementChanged(PerspexPropertyChangedEventArgs e)
        {
            var adorner = (Visual)e.Sender;
            var adorned = (Visual)e.NewValue;
            var layer   = adorner.GetVisualParent <AdornerLayer>();

            layer?.UpdateAdornedElement(adorner, adorned);
        }
Beispiel #16
0
        /// <inheritdoc/>
        protected override void OnTemplateChanged(PerspexPropertyChangedEventArgs e)
        {
            base.OnTemplateChanged(e);

            if (e.NewValue == null)
            {
                ItemContainerGenerator?.Clear();
            }
        }
Beispiel #17
0
 /// <summary>
 /// Called when the <see cref="SelectingItemsControl.SelectedIndex"/> property changes.
 /// </summary>
 /// <param name="e">The event args.</param>
 private void SelectedIndexChanged(PerspexPropertyChangedEventArgs e)
 {
     if ((int)e.NewValue != -1)
     {
         var item = SelectedItem as IContentControl;
         var content = item?.Content ?? item;
         SelectedTab = item as TabItem;
     }
 }
Beispiel #18
0
        /// <summary>
        /// Called when the <see cref="IsSelected"/> property changes on an object.
        /// </summary>
        /// <param name="e">The sender.</param>
        private static void IsSelectedChanged(PerspexPropertyChangedEventArgs e)
        {
            var interactive = e.Sender as IInteractive;

            if (interactive != null)
            {
                interactive.RaiseEvent(new RoutedEventArgs(SelectingItemsControl.IsSelectedChangedEvent));
            }
        }
Beispiel #19
0
 /// <summary>
 /// Called when the <see cref="SelectingItemsControl.SelectedIndex"/> property changes.
 /// </summary>
 /// <param name="e">The event args.</param>
 private void SelectedIndexChanged(PerspexPropertyChangedEventArgs e)
 {
     if ((int)e.NewValue != -1)
     {
         var item    = SelectedItem as IContentControl;
         var content = item?.Content ?? item;
         SelectedTab = item as TabItem;
     }
 }
Beispiel #20
0
        /// <summary>
        /// Calls <see cref="InvalidateArrange"/> on the control on which a property changed.
        /// </summary>
        /// <param name="e">The event args.</param>
        private static void AffectsArrangeInvalidate(PerspexPropertyChangedEventArgs e)
        {
            ILayoutable control = e.Sender as ILayoutable;

            if (control != null)
            {
                control.InvalidateArrange();
            }
        }
Beispiel #21
0
        /// <summary>
        /// Called when the <see cref="Template"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void OnTemplateChanged(PerspexPropertyChangedEventArgs e)
        {
            if (_templateApplied && VisualChildren.Count > 0)
            {
                _templateApplied = false;
            }

            _templateApplied = false;
            InvalidateMeasure();
        }
        private void OnSizeGripChanged(PerspexPropertyChangedEventArgs e)
        {
            var thumb = (e.Sender as Thumb);

            if (thumb == null)
            {
                return;
            }
            thumb.DragDelta += SizeThumbOnDragDelta;
        }
Beispiel #23
0
 /// <summary>
 /// Called when the <see cref="IsOpen"/> property changes.
 /// </summary>
 /// <param name="e">The event args.</param>
 private void IsOpenChanged(PerspexPropertyChangedEventArgs e)
 {
     if ((bool)e.NewValue)
     {
         Open();
     }
     else
     {
         Close();
     }
 }
Beispiel #24
0
        /// <summary>
        /// Called when the <see cref="Child"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private void ChildChanged(PerspexPropertyChangedEventArgs e)
        {
            LogicalChildren.Clear();

            ((ISetLogicalParent)e.OldValue)?.SetParent(null);

            if (e.NewValue != null)
            {
                ((ISetLogicalParent)e.NewValue).SetParent(this);
                LogicalChildren.Add((ILogical)e.NewValue);
            }
        }
Beispiel #25
0
        /// <summary>
        /// Reacts to a change in a <see cref="PerspexProperty"/> value in order to animate the
        /// change if a <see cref="PropertyTransition"/> is set for the property..
        /// </summary>
        /// <param name="e">The event args.</param>
        protected override void OnPropertyChanged(PerspexPropertyChangedEventArgs e)
        {
            if (e.Priority != BindingPriority.Animation && _propertyTransitions != null)
            {
                var match = _propertyTransitions.FirstOrDefault(x => x.Property == e.Property);

                if (match != null)
                {
                    Animate.Property(this, e.Property, e.OldValue, e.NewValue, match.Easing, match.Duration);
                }
            }
        }
Beispiel #26
0
        /// <summary>
        /// Reacts to a change in a <see cref="PerspexProperty"/> value in order to animate the
        /// change if a <see cref="PropertyTransition"/> is set for the property..
        /// </summary>
        /// <param name="e">The event args.</param>
        protected override void OnPropertyChanged(PerspexPropertyChangedEventArgs e)
        {
            if (e.Priority != BindingPriority.Animation && _propertyTransitions != null)
            {
                var match = _propertyTransitions.FirstOrDefault(x => x.Property == e.Property);

                if (match != null)
                {
                    Animate.Property(this, e.Property, e.OldValue, e.NewValue, match.Easing, match.Duration);
                }
            }
        }
Beispiel #27
0
        /// <summary>
        /// Caled when the <see cref="Items"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void ItemsChanged(PerspexPropertyChangedEventArgs e)
        {
            var incc = e.OldValue as INotifyCollectionChanged;

            if (incc != null)
            {
                incc.CollectionChanged -= ItemsCollectionChanged;
            }

            var newValue = e.NewValue as IEnumerable;

            SubscribeToItems(newValue);
        }
        /// <inheritdoc/>
        protected override void ItemsChanged(PerspexPropertyChangedEventArgs e)
        {
            base.ItemsChanged(e);

            if (SelectedIndex != -1)
            {
                SelectedIndex = IndexOf((IEnumerable)e.NewValue, SelectedItem);
            }
            else if (AlwaysSelected && Items != null && Items.Cast <object>().Any())
            {
                SelectedIndex = 0;
            }
        }
Beispiel #29
0
        /// <summary>
        /// called when the <see cref="ContextMenuProperty"/> property changes on a control.
        /// </summary>
        /// <param name="e">The event args.</param>
        private static void ContextMenuChanged(PerspexPropertyChangedEventArgs e)
        {
            var control = (Control)e.Sender;

            if (e.OldValue != null)
            {
                control.PointerReleased -= ControlPointerReleased;
            }

            if (e.NewValue != null)
            {
                control.PointerReleased += ControlPointerReleased;
            }
        }
Beispiel #30
0
        /// <summary>
        /// Called when the <see cref="Control.ContextMenu"/> property changes on a control.
        /// </summary>
        /// <param name="e">The event args.</param>
        private static void ContextMenuChanged(PerspexPropertyChangedEventArgs e)
        {
            var control = (Control)e.Sender;

            if (e.OldValue != null)
            {
                control.PointerReleased -= ControlPointerReleased;
            }

            if (e.NewValue != null)
            {
                control.PointerReleased += ControlPointerReleased;
            }
        }
Beispiel #31
0
        /// <summary>
        /// Called when the <see cref="IsSubMenuOpen"/> property changes.
        /// </summary>
        /// <param name="e">The property change event.</param>
        private void SubMenuOpenChanged(PerspexPropertyChangedEventArgs e)
        {
            var value = (bool)e.NewValue;

            if (value)
            {
                RaiseEvent(new RoutedEventArgs(SubmenuOpenedEvent));
                IsSelected = true;
            }
            else
            {
                CloseSubmenus();
                SelectedIndex = -1;
            }
        }
Beispiel #32
0
        /// <summary>
        /// Called when the <see cref="Icon"/> property changes.
        /// </summary>
        /// <param name="e">The property change event.</param>
        private void IconChanged(PerspexPropertyChangedEventArgs e)
        {
            var oldValue = e.OldValue as ILogical;
            var newValue = e.NewValue as ILogical;

            if (oldValue != null)
            {
                LogicalChildren.Remove(oldValue);
            }

            if (newValue != null)
            {
                LogicalChildren.Add(newValue);
            }
        }
Beispiel #33
0
        /// <summary>
        /// called when the <see cref="TipProperty"/> property changes on a control.
        /// </summary>
        /// <param name="e">The event args.</param>
        private static void TipChanged(PerspexPropertyChangedEventArgs e)
        {
            var control = (Control)e.Sender;

            if (e.OldValue != null)
            {
                control.PointerEnter -= ControlPointerEnter;
                control.PointerLeave -= ControlPointerLeave;
            }

            if (e.NewValue != null)
            {
                control.PointerEnter += ControlPointerEnter;
                control.PointerLeave += ControlPointerLeave;
            }
        }
Beispiel #34
0
        /// <summary>
        /// Caled when the <see cref="Items"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void ItemsChanged(PerspexPropertyChangedEventArgs e)
        {
            var incc = e.OldValue as INotifyCollectionChanged;

            if (incc != null)
            {
                incc.CollectionChanged -= ItemsCollectionChanged;
            }

            var oldValue = e.OldValue as IEnumerable;
            var newValue = e.NewValue as IEnumerable;

            RemoveControlItemsFromLogicalChildren(oldValue);
            AddControlItemsToLogicalChildren(newValue);
            SubscribeToItems(newValue);
        }
Beispiel #35
0
        /// <summary>
        /// called when the <see cref="TipProperty"/> property changes on a control.
        /// </summary>
        /// <param name="e">The event args.</param>
        private static void TipChanged(PerspexPropertyChangedEventArgs e)
        {
            var control = (Control)e.Sender;

            if (e.OldValue != null)
            {
                control.PointerEnter -= ControlPointerEnter;
                control.PointerLeave -= ControlPointerLeave;
            }

            if (e.NewValue != null)
            {
                control.PointerEnter += ControlPointerEnter;
                control.PointerLeave += ControlPointerLeave;
            }
        }
Beispiel #36
0
        /// <summary>
        /// Called when the <see cref="IsDefault"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private static void IsDefaultChanged(PerspexPropertyChangedEventArgs e)
        {
            var button    = e.Sender as Button;
            var isDefault = (bool)e.NewValue;
            var inputRoot = button.VisualRoot as IInputElement;

            if (inputRoot != null)
            {
                if (isDefault)
                {
                    button.ListenForDefault(inputRoot);
                }
                else
                {
                    button.StopListeningForDefault(inputRoot);
                }
            }
        }
Beispiel #37
0
        protected virtual void OnIsExpandedChanged(PerspexPropertyChangedEventArgs e)
        {
            IVisual visualContent = Presenter;

            if (Content != null && ContentTransition != null && visualContent != null)
            {
                bool forward = ExpandDirection == ExpandDirection.Left ||
                                ExpandDirection == ExpandDirection.Up;
                if (IsExpanded)
                {
                    ContentTransition.Start(null, visualContent, forward);
                }
                else
                {
                    ContentTransition.Start(visualContent, null, !forward);
                }
            }
        }
Beispiel #38
0
        protected virtual void OnIsExpandedChanged(PerspexPropertyChangedEventArgs e)
        {
            IVisual visualContent = Presenter;

            if (Content != null && ContentTransition != null && visualContent != null)
            {
                bool forward = ExpandDirection == ExpandDirection.Left ||
                               ExpandDirection == ExpandDirection.Up;
                if (IsExpanded)
                {
                    ContentTransition.Start(null, visualContent, forward);
                }
                else
                {
                    ContentTransition.Start(visualContent, null, !forward);
                }
            }
        }
Beispiel #39
0
        /// <summary>
        /// Called when the <see cref="Child"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private void ChildChanged(PerspexPropertyChangedEventArgs e)
        {
            var oldChild = (Control)e.OldValue;
            var newChild = (Control)e.NewValue;

            if (oldChild != null)
            {
                ((ISetLogicalParent)oldChild).SetParent(null);
                LogicalChildren.Clear();
                RemoveVisualChild(oldChild);
            }

            if (newChild != null)
            {
                AddVisualChild(newChild);
                LogicalChildren.Add(newChild);
                ((ISetLogicalParent)newChild).SetParent(this);
            }
        }
Beispiel #40
0
        private static void ItemsChanged(PerspexPropertyChangedEventArgs e)
        {
            var grid = (Grid)e.Sender;
            var items = (IEnumerable)e.NewValue;
            var template = grid.GetValue(TemplateProperty);

            grid.Children.Clear();

            if (items != null)
            {
                int count = 0;
                int cols = grid.ColumnDefinitions.Count;

                foreach (var item in items)
                {
                    foreach (var control in template(item))
                    {
                        grid.Children.Add(control);
                        Grid.SetColumn(control, count % cols);
                        Grid.SetRow(control, count / cols);
                        ++count;
                    }
                }

                int rows = (int)Math.Ceiling((double)count / cols);
                int difference = rows - grid.RowDefinitions.Count;

                if (difference > 0)
                {
                    for (int i = 0; i < difference; ++i)
                    {
                        grid.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
                    }
                }
                else if (difference < 0)
                {
                    for (int i = 0; i < difference; ++i)
                    {
                        grid.RowDefinitions.RemoveAt(grid.RowDefinitions.Count - 1);
                    }
                }
            }
        }
Beispiel #41
0
        private void OnLayoutTransformChanged(PerspexPropertyChangedEventArgs e)
        {
            var newTransform = e.NewValue as Transform;

            if (_transformChangedEvent != null)
            {
                _transformChangedEvent.Dispose();
                _transformChangedEvent = null;
            }

            if (newTransform != null)
            {
                _transformChangedEvent         = Observable.FromEventPattern <EventHandler, EventArgs>(
                    v => newTransform.Changed += v, v => newTransform.Changed -= v)
                                                 .Subscribe(onNext: v => ApplyLayoutTransform());
            }

            ApplyLayoutTransform();
        }
Beispiel #42
0
        /// <summary>
        /// Called when the <see cref="IsDefault"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private static void IsDefaultChanged(PerspexPropertyChangedEventArgs e)
        {
            var button       = e.Sender as Button;
            var isDefault    = (bool)e.NewValue;
            var root         = button.GetSelfAndVisualAncestors().OfType <IRenderRoot>().FirstOrDefault();
            var inputElement = root as IInputElement;

            if (inputElement != null)
            {
                if (isDefault)
                {
                    button.ListenForDefault(inputElement);
                }
                else
                {
                    button.StopListeningForDefault(inputElement);
                }
            }
        }
 /// <summary>
 /// Called when the <see cref="SelectedItem"/> property changes.
 /// </summary>
 /// <param name="e">The event args.</param>
 private void SelectedItemChanged(PerspexPropertyChangedEventArgs e)
 {
     SelectedIndex = IndexOf(Items, e.NewValue);
 }
        /// <summary>
        /// Called when the <see cref="SelectedIndex"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private void SelectedIndexChanged(PerspexPropertyChangedEventArgs e)
        {
            var index = (int)e.OldValue;

            if (index != -1)
            {
                var container = ItemContainerGenerator.ContainerFromIndex(index);
                MarkContainerSelected(container, false);
            }

            index = (int)e.NewValue;

            if (index == -1)
            {
                SelectedItem = null;
            }
            else
            {
                SelectedItem = Items.Cast<object>().ElementAt((int)e.NewValue);
                var container = ItemContainerGenerator.ContainerFromIndex(index);
                MarkContainerSelected(container, true);

                var inputElement = container as IInputElement;
                if (inputElement != null && Presenter != null && Presenter.Panel != null)
                {
                    KeyboardNavigation.SetTabOnceActiveElement(
                        (InputElement)Presenter.Panel,
                        inputElement);
                }
            }
        }
        /// <inheritdoc/>
        protected override void ItemsChanged(PerspexPropertyChangedEventArgs e)
        {
            base.ItemsChanged(e);

            if (SelectedIndex != -1)
            {
                SelectedIndex = IndexOf((IEnumerable)e.NewValue, SelectedItem);
            }
            else if (AutoSelect && Items != null & Items.Cast<object>().Any())
            {
                SelectedIndex = 0;
            }
        }
Beispiel #46
0
        /// <summary>
        /// Called when the <see cref="IsSubMenuOpen"/> property changes.
        /// </summary>
        /// <param name="e">The property change event.</param>
        private void SubMenuOpenChanged(PerspexPropertyChangedEventArgs e)
        {
            var value = (bool)e.NewValue;

            if (value)
            {
                this.RaiseEvent(new RoutedEventArgs(SubmenuOpenedEvent));
                this.IsSelected = true;
            }
            else
            {
                this.CloseSubmenus();
                this.SelectedIndex = -1;
            }
        }
Beispiel #47
0
 private void SelectedItemChanged(PerspexPropertyChangedEventArgs e)
 {
     UpdateSelectionBoxItem(e.NewValue);
 }
Beispiel #48
0
        /// <summary>
        /// Called when the <see cref="IsDefault"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private static void IsDefaultChanged(PerspexPropertyChangedEventArgs e)
        {
            var button = e.Sender as Button;
            var isDefault = (bool)e.NewValue;
            var root = button.GetSelfAndVisualAncestors().OfType<IRenderRoot>().FirstOrDefault();
            var inputElement = root as IInputElement;

            if (inputElement != null)
            {
                if (isDefault)
                {
                    button.ListenForDefault(inputElement);
                }
                else
                {
                    button.StopListeningForDefault(inputElement);
                }
            }
        }
Beispiel #49
0
        /// <summary>
        /// Called when the <see cref="Child"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private void ChildChanged(PerspexPropertyChangedEventArgs e)
        {
            LogicalChildren.Clear();

            if (e.OldValue != null)
            {
                ((ISetLogicalParent)e.OldValue).SetParent(null);
            }

            if (e.NewValue != null)
            {
                ((ISetLogicalParent)e.NewValue).SetParent(this);
                LogicalChildren.Add((ILogical)e.NewValue);
            }
        }
 /// <summary>
 /// Called when the <see cref="Content"/> property changes.
 /// </summary>
 /// <param name="e">The event args.</param>
 private void ContentChanged(PerspexPropertyChangedEventArgs e)
 {
     _createdChild = false;
     InvalidateMeasure();
 }
Beispiel #51
0
        /// <summary>
        /// Called when the <see cref="Items"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private void ItemsChanged(PerspexPropertyChangedEventArgs e)
        {
            if (_createdPanel)
            {
                var generator = ItemContainerGenerator;

                if (e.OldValue != null)
                {
                    generator.ClearContainers();
                    Panel.Children.Clear();

                    INotifyCollectionChanged incc = e.OldValue as INotifyCollectionChanged;

                    if (incc != null)
                    {
                        incc.CollectionChanged -= ItemsCollectionChanged;
                    }
                }

                if (Panel != null)
                {
                    CreateItemsAndListenForChanges((IEnumerable)e.NewValue);
                }
            }
        }
Beispiel #52
0
        /// <summary>
        /// Caled when the <see cref="Items"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void ItemsChanged(PerspexPropertyChangedEventArgs e)
        {
            var incc = e.OldValue as INotifyCollectionChanged;

            if (incc != null)
            {
                incc.CollectionChanged += this.ItemsCollectionChanged;
            }

            var newValue = e.NewValue as IEnumerable;

            if (newValue == null || newValue.Count() == 0)
            {
                this.Classes.Add(":empty");
            }
            else
            {
                this.Classes.Remove(":empty");
            }

            incc = newValue as INotifyCollectionChanged;

            if (incc != null)
            {
                incc.CollectionChanged += this.ItemsCollectionChanged;
            }
        }
Beispiel #53
0
 /// <summary>
 /// Called when the <see cref="SelectingItemsControl.SelectedIndex"/> property changes.
 /// </summary>
 /// <param name="e">The event args.</param>
 private void SelectedItemChanged(PerspexPropertyChangedEventArgs e)
 {
     var item = e.NewValue as IContentControl;
     var content = item?.Content ?? item;
     SelectedTab = item as TabItem;
 }
Beispiel #54
0
        private void SelectedItemChanged(PerspexPropertyChangedEventArgs e)
        {
            var control = e.NewValue as IControl;

            if (control != null)
            {
                SelectionBoxItem = new Rectangle
                {
                    Width = control.DesiredSize.Width,
                    Height = control.DesiredSize.Height,
                    Fill = new VisualBrush
                    {
                        Visual = control,
                        Stretch = Stretch.None,
                        AlignmentX = AlignmentX.Left,
                    }
                };
            }
            else
            {
                SelectionBoxItem = e.NewValue;
            }
        }
Beispiel #55
0
 /// <summary>
 /// Called when the <see cref="SelectedIndex"/> property changes.
 /// </summary>
 /// <param name="e">The event args.</param>
 private void SelectedIndexChanged(PerspexPropertyChangedEventArgs e)
 {
     if (Panel != null)
     {
         var task = MoveToPage((int)e.OldValue, (int)e.NewValue);
     }
 }
Beispiel #56
0
        /// <summary>
        /// Called when the <see cref="Command"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private static void CommandChanged(PerspexPropertyChangedEventArgs e)
        {
            var button = e.Sender as Button;

            if (button != null)
            {
                var oldCommand = e.OldValue as ICommand;
                var newCommand = e.NewValue as ICommand;

                if (oldCommand != null)
                {
                    oldCommand.CanExecuteChanged -= button.CanExecuteChanged;
                }

                if (newCommand != null)
                {
                    newCommand.CanExecuteChanged += button.CanExecuteChanged;
                }

                button.CanExecuteChanged(button, EventArgs.Empty);
            }
        }
        /// <summary>
        /// Called when the <see cref="SelectedIndex"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private static void SelectedIndexChanged(PerspexPropertyChangedEventArgs e)
        {
            var control = e.Sender as SelectingItemsControl;

            if (control != null)
            {
                var index = (int)e.NewValue;

                if (index == -1)
                {
                    control.SelectedItem = null;
                }
                else
                {
                    control.SelectedItem = control.Items.ElementAt((int)e.NewValue);
                }
            }
        }
Beispiel #58
0
 /// <summary>
 /// Called when the <see cref="IsOpen"/> property changes.
 /// </summary>
 /// <param name="e">The event args.</param>
 private void IsOpenChanged(PerspexPropertyChangedEventArgs e)
 {
     if ((bool)e.NewValue)
     {
         Open();
     }
     else
     {
         Close();
     }
 }
Beispiel #59
0
 private static void IsEnabledChanged(PerspexPropertyChangedEventArgs e)
 {
     ((InputElement)e.Sender).UpdateIsEnabledCore();
 }
        /// <summary>
        /// Called when the <see cref="SelectedItem"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private static void SelectedItemChanged(PerspexPropertyChangedEventArgs e)
        {
            var control = e.Sender as SelectingItemsControl;

            if (control != null)
            {
                control.SelectedItemChanged(e.NewValue);
            }
        }