Example #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);
 }
Example #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;
            }
        }
Example #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);
     }
 }
Example #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);
     }
 }
Example #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();
        }
Example #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;
            }
        }
Example #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);
                }
            }
        }
Example #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;
                }
            }
        }
Example #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;
        }
Example #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);
                }
            }
        }
Example #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;
     }
 }
Example #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;
     }
 }
Example #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;
     }
 }
Example #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);
        }
Example #16
0
        /// <inheritdoc/>
        protected override void OnTemplateChanged(PerspexPropertyChangedEventArgs e)
        {
            base.OnTemplateChanged(e);

            if (e.NewValue == null)
            {
                ItemContainerGenerator?.Clear();
            }
        }
Example #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;
     }
 }
Example #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));
            }
        }
Example #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;
     }
 }
Example #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();
            }
        }
Example #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;
        }
Example #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();
     }
 }
Example #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);
            }
        }
Example #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);
                }
            }
        }
Example #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);
                }
            }
        }
Example #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);
        }
Example #28
0
        /// <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;
            }
        }
Example #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;
            }
        }
Example #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;
            }
        }
Example #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;
            }
        }
Example #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);
            }
        }
Example #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;
            }
        }
Example #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);
        }
Example #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;
            }
        }
Example #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);
                }
            }
        }
Example #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);
                }
            }
        }
Example #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);
                }
            }
        }
Example #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);
            }
        }
Example #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);
                    }
                }
            }
        }
Example #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();
        }
Example #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);
                }
            }
        }
Example #43
0
 /// <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);
 }
Example #44
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);
                }
            }
        }
Example #45
0
        /// <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;
            }
        }
Example #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;
            }
        }
Example #47
0
 private void SelectedItemChanged(PerspexPropertyChangedEventArgs e)
 {
     UpdateSelectionBoxItem(e.NewValue);
 }
Example #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);
                }
            }
        }
Example #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();
 }
Example #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);
                }
            }
        }
Example #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;
            }
        }
Example #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;
 }
Example #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;
            }
        }
Example #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);
     }
 }
Example #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);
                }
            }
        }
Example #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();
     }
 }
Example #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);
            }
        }