Example #1
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();
             }
         }
     }
 }
Example #2
0
        private static int ValidateCaretIndex(PerspexObject o, int value)
        {
            var text   = o.GetValue(TextProperty);
            var length = (text != null) ? text.Length : 0;

            return(Math.Max(0, Math.Min(length, value)));
        }
Example #3
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();
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Called when the <see cref="DataContext"/> property begins and ends being notified.
        /// </summary>
        /// <param name="o">The object on which the DataContext is changing.</param>
        /// <param name="notifying">Whether the notifcation is beginning or ending.</param>
        private static void DataContextNotifying(PerspexObject o, bool notifying)
        {
            var control = o as Control;

            if (control != null)
            {
                control.IsDataContextChanging = notifying;
            }
        }
            public Accessor(PerspexObject instance, PerspexProperty property, Action<object> changed)
            {
                Contract.Requires<ArgumentNullException>(instance != null);
                Contract.Requires<ArgumentNullException>(property != null);

                _instance = instance;
                _property = property;
                _subscription = instance.GetObservable(property).Skip(1).Subscribe(changed);
            }
Example #6
0
        private static int ValidateRow(PerspexObject o, int value)
        {
            if (value < 0)
            {
                throw new ArgumentException("Invalid Grid.Row value.");
            }

            return(value);
        }
Example #7
0
            public Accessor(PerspexObject instance, PerspexProperty property, Action <object> changed)
            {
                Contract.Requires <ArgumentNullException>(instance != null);
                Contract.Requires <ArgumentNullException>(property != null);

                _instance     = instance;
                _property     = property;
                _subscription = instance.GetObservable(property).Skip(1).Subscribe(changed);
            }
Example #8
0
        private void HandleXamlBindingDefinition(XamlBindingDefinition xamlBindingDefinition)
        {
            PerspexObject subjectObject = xamlBindingDefinition.Target;

            _propertyBinder.Create(xamlBindingDefinition);

            var observableForDataContext = subjectObject.GetObservable(Control.DataContextProperty);

            observableForDataContext.Where(o => o != null).Subscribe(_ => BindToDataContextWhenItsSet(xamlBindingDefinition));
        }
 public PerspexPropertyChangedEventArgs(
     PerspexObject sender,
     PerspexProperty property,
     object oldValue,
     object newValue)
 {
     this.Sender   = sender;
     this.Property = property;
     this.OldValue = oldValue;
     this.NewValue = newValue;
 }
Example #10
0
        public ControlDetails(IVisual visual)
        {
            PerspexObject po = visual as PerspexObject;

            if (po != null)
            {
                this.Properties = po.GetAllValues()
                                  .Select(x => new PropertyDetails(x))
                                  .OrderBy(x => x.Name);
            }
        }
Example #11
0
        /// <summary>
        /// Animates a <see cref="PerspexProperty"/>.
        /// </summary>
        /// <typeparam name="T">The property type.</typeparam>
        /// <param name="target">The target object.</param>
        /// <param name="property">The target property.</param>
        /// <param name="start">The value of the property at the start of the animation.</param>
        /// <param name="finish">The value of the property at the end of the animation.</param>
        /// <param name="easing">The easing function to use.</param>
        /// <param name="duration">The duration of the animation.</param>
        /// <returns>An <see cref="IDisposable"/> that can be used to stop the animation.</returns>
        public static IDisposable Property(
            PerspexObject target,
            PerspexProperty property,
            object start,
            object finish,
            IEasing easing,
            TimeSpan duration)
        {
            var o = GetTimer(duration).Select(progress => easing.Ease(progress, start, finish));

            return(target.Bind(property, o, BindingPriority.Animation));
        }
        public DataContextChangeSynchronizer(PerspexObject target, PerspexProperty targetProperty,
            PropertyPath sourcePropertyPath, object source, ITypeConverterProvider typeConverterProvider)
        {
            Guard.ThrowIfNull(target, nameof(target));
            Guard.ThrowIfNull(targetProperty, nameof(targetProperty));
            Guard.ThrowIfNull(sourcePropertyPath, nameof(sourcePropertyPath));
            Guard.ThrowIfNull(source, nameof(source));
            Guard.ThrowIfNull(typeConverterProvider, nameof(typeConverterProvider));

            this.bindingEndpoint = new TargetBindingEndpoint(target, targetProperty);
            this.sourceEndpoint = new ObservablePropertyBranch(source, sourcePropertyPath);
            this.targetPropertyTypeConverter = typeConverterProvider.GetTypeConverter(targetProperty.PropertyType);
        }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PerspexPropertyChangedEventArgs"/> class.
 /// </summary>
 /// <param name="sender">The object that the property changed on.</param>
 /// <param name="property">The property that changed.</param>
 /// <param name="oldValue">The old value of the property.</param>
 /// <param name="newValue">The new value of the property.</param>
 /// <param name="priority">The priority of the binding that produced the value.</param>
 public PerspexPropertyChangedEventArgs(
     PerspexObject sender,
     PerspexProperty property,
     object oldValue,
     object newValue,
     BindingPriority priority)
 {
     Sender   = sender;
     Property = property;
     OldValue = oldValue;
     NewValue = newValue;
     Priority = priority;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PerspexPropertyChangedEventArgs"/> class.
 /// </summary>
 /// <param name="sender">The object that the property changed on.</param>
 /// <param name="property">The property that changed.</param>
 /// <param name="oldValue">The old value of the property.</param>
 /// <param name="newValue">The new value of the property.</param>
 /// <param name="priority">The priority of the binding that produced the value.</param>
 public PerspexPropertyChangedEventArgs(
     PerspexObject sender,
     PerspexProperty property,
     object oldValue,
     object newValue,
     BindingPriority priority)
 {
     this.Sender = sender;
     this.Property = property;
     this.OldValue = oldValue;
     this.NewValue = newValue;
     this.Priority = priority;
 }
Example #15
0
        private static Vector ValidateOffset(PerspexObject o, Vector value)
        {
            ScrollViewer scrollViewer = o as ScrollViewer;

            if (scrollViewer != null)
            {
                var extent   = scrollViewer.Extent;
                var viewport = scrollViewer.Viewport;
                return(CoerceOffset(extent, viewport, value));
            }
            else
            {
                return(value);
            }
        }
Example #16
0
        private static Vector CoerceOffset(PerspexObject o, Vector value)
        {
            ScrollViewer scrollViewer = o as ScrollViewer;

            if (scrollViewer != null)
            {
                var extent   = scrollViewer.Extent;
                var viewport = scrollViewer.Viewport;
                var maxX     = Math.Max(extent.Width - viewport.Width, 0);
                var maxY     = Math.Max(extent.Height - viewport.Height, 0);
                return(new Vector(Clamp(value.X, 0, maxX), Clamp(value.Y, 0, maxY)));
            }
            else
            {
                return(value);
            }
        }
Example #17
0
        public PropertyDetails(PerspexObject o, PerspexProperty property)
        {
            Name = property.IsAttached ?
                   $"[{property.OwnerType.Name}.{property.Name}]" :
                   property.Name;
            IsAttached = property.IsAttached;

            // TODO: Unsubscribe when view model is deactivated.
            o.GetObservable(property).Subscribe(x =>
            {
                var diagnostic = o.GetDiagnostic(property);
                Value          = diagnostic.Value ?? "(null)";
                Priority       = (diagnostic.Priority != BindingPriority.Unset) ?
                                 diagnostic.Priority.ToString() :
                                 diagnostic.Property.Inherits ? "Inherited" : "Unset";
                Diagnostic = diagnostic.Diagnostic;
            });
        }
Example #18
0
        public PropertyDetails(PerspexObject o, PerspexProperty property)
        {
            Name = property.IsAttached ?
                $"[{property.OwnerType.Name}.{property.Name}]" :
                property.Name;
            IsAttached = property.IsAttached;

            // TODO: Unsubscribe when view model is deactivated.
            o.GetObservable(property).Subscribe(x =>
            {
                var diagnostic = o.GetDiagnostic(property);
                Value = diagnostic.Value ?? "(null)";
                Priority = (diagnostic.Priority != BindingPriority.Unset) ?
                    diagnostic.Priority.ToString() :
                    diagnostic.Property.Inherits ? "Inherited" : "Unset";
                Diagnostic = diagnostic.Diagnostic;
            });
        }
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var s       = (string)value;
            var lastDot = s.LastIndexOf('.');

            if (lastDot == -1)
            {
                throw new NotSupportedException("PerspexProperties must currently be fully qualified.");
            }

            var typeName     = s.Substring(0, lastDot);
            var propertyName = s.Substring(lastDot + 1);
            var type         = context.TypeRepository.GetByQualifiedName(typeName)?.UnderlyingType;
            var styleType    = context.TypeRepository.GetXamlType(typeof(Style));

            // ATTN: SuperJMN
            //var style = ((XamlTypeConverterContext)context).TopDownValueContext.GetLastInstance(styleType);

            if (type == null)
            {
                throw new XamlParseException($"Could not find type '{typeName}'.");
            }

            // First look for non-attached property on the type and then look for an attached property.
            var property = PerspexObject.GetRegisteredProperties(type)
                           .FirstOrDefault(x => x.Name == propertyName);

            if (property == null)
            {
                property = PerspexObject.GetAttachedProperties(type)
                           .FirstOrDefault(x => x.Name == propertyName);
            }

            if (property == null)
            {
                throw new XamlParseException(
                          $"Could not find PerspexProperty '{typeName}'.{propertyName}.");
            }

            return(property);
        }
Example #20
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 HtmlControl;

            if (control != null)
            {
                var htmlContainer = control._htmlContainer;
                if (e.Property == AvoidImagesLateLoadingProperty)
                {
                    htmlContainer.AvoidImagesLateLoading = (bool)e.NewValue;
                }
                else if (e.Property == IsSelectionEnabledProperty)
                {
                    htmlContainer.IsSelectionEnabled = (bool)e.NewValue;
                }
                else if (e.Property == IsContextMenuEnabledProperty)
                {
                    htmlContainer.IsContextMenuEnabled = (bool)e.NewValue;
                }
                else if (e.Property == BaseStylesheetProperty)
                {
                    var baseCssData = CssData.Parse(PerspexAdapter.Instance, (string)e.NewValue);
                    control._baseCssData = baseCssData;
                    htmlContainer.SetHtml(control.Text, baseCssData);
                }
                else if (e.Property == TextProperty)
                {
                    htmlContainer.ScrollOffset = new Point(0, 0);
                    htmlContainer.SetHtml((string)e.NewValue, control._baseCssData);
                    control.InvalidateMeasure();
                    control.InvalidateVisual();

                    if (control.VisualRoot != null)
                    {
                        control.InvokeMouseMove();
                    }
                }
            }
        }
Example #21
0
        /// <summary>
        /// Gets a diagnostic for a <see cref="PerspexProperty"/> on a <see cref="PerspexObject"/>.
        /// </summary>
        /// <param name="o">The object.</param>
        /// <param name="property">The property.</param>
        /// <returns>
        /// A <see cref="PerspexPropertyValue"/> that can be used to diagnose the state of the
        /// property on the object.
        /// </returns>
        public static PerspexPropertyValue GetDiagnostic(this PerspexObject o, PerspexProperty property)
        {
            var set = o.GetSetValues();

            PriorityValue value;

            if (set.TryGetValue(property, out value))
            {
                return(new PerspexPropertyValue(
                           property,
                           o.GetValue(property),
                           (BindingPriority)value.ValuePriority,
                           value.GetDiagnostic()));
            }
            else
            {
                return(new PerspexPropertyValue(
                           property,
                           o.GetValue(property),
                           BindingPriority.Unset,
                           "Unset"));
            }
        }
Example #22
0
 public static void SetRowSpan(PerspexObject element, int value)
 {
     element.SetValue(RowSpanProperty, value);
 }
Example #23
0
 public XamlBinding GetBinding(PerspexObject po, PerspexProperty pp)
 {
     return this.bindings.First(xamlBinding => xamlBinding.Target == po && xamlBinding.TargetProperty == pp);
 }
Example #24
0
 public IDisposable BindTwoWay(PerspexProperty property, PerspexObject source, PerspexProperty sourceProperty, BindingPriority priority = BindingPriority.LocalValue)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Finds a registered property on an object by name.
 /// </summary>
 /// <param name="o">The object.</param>
 /// <param name="name">
 /// The property name. If an attached property it should be in the form 
 /// "OwnerType.PropertyName".
 /// </param>
 /// <returns>
 /// The registered property or null if no matching property found.
 /// </returns>
 public PerspexProperty FindRegistered(PerspexObject o, string name)
 {
     return FindRegistered(o.GetType(), name);
 }
Example #26
0
        private static Vector ValidateOffset(PerspexObject o, Vector value)
        {
            ScrollViewer scrollViewer = o as ScrollViewer;

            if (scrollViewer != null)
            {
                var extent = scrollViewer.Extent;
                var viewport = scrollViewer.Viewport;
                var maxX = Math.Max(extent.Width - viewport.Width, 0);
                var maxY = Math.Max(extent.Height - viewport.Height, 0);
                return new Vector(Clamp(value.X, 0, maxX), Clamp(value.Y, 0, maxY));
            }
            else
            {
                return value;
            }
        }
Example #27
0
 /// <summary>
 /// Gets the value of the Right attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <returns>The control's right coordinate.</returns>
 public static double GetRight(PerspexObject element)
 {
     return element.GetValue(RightProperty);
 }
Example #28
0
 /// <summary>
 /// Sets the value of the Bottom attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <param name="value">The bottom value.</param>
 public static void SetBottom(PerspexObject element, double value)
 {
     element.SetValue(BottomProperty, value);
 }
Example #29
0
 /// <summary>
 /// Gets the value of the Bottom attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <returns>The control's bottom coordinate.</returns>
 public static double GetBottom(PerspexObject element)
 {
     return(element.GetValue(BottomProperty));
 }
Example #30
0
 /// <summary>
 /// Gets the value of the Bottom attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <returns>The control's bottom coordinate.</returns>
 public static double GetBottom(PerspexObject element)
 {
     return element.GetValue(BottomProperty);
 }
Example #31
0
 /// <summary>
 /// Sets the value of the Bottom attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <param name="value">The bottom value.</param>
 public static void SetBottom(PerspexObject element, double value)
 {
     element.SetValue(BottomProperty, value);
 }
Example #32
0
 public static void SetHotKey(PerspexObject target, KeyGesture value) => target.SetValue(HotKeyProperty, value);
Example #33
0
 /// <summary>
 /// Gets the value of the Left attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <returns>The control's left coordinate.</returns>
 public static double GetLeft(PerspexObject element)
 {
     return element.GetValue(LeftProperty);
 }
Example #34
0
 public static KeyGesture GetHotKey(PerspexObject target) => target.GetValue(HotKeyProperty);
 public BindingTarget(PerspexObject @object, PerspexProperty property)
 {
     _obj = @object;
     _property = property;
 }
Example #36
0
 /// <summary>
 /// Sets the value of the Left attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <param name="value">The left value.</param>
 public static void SetLeft(PerspexObject element, double value)
 {
     element.SetValue(LeftProperty, value);
 }
Example #37
0
 private static int Coerce(PerspexObject instance, int value)
 {
     return(Math.Min(Math.Max(value, 0), ((Class1)instance).MaxQux));
 }
Example #38
0
 /// <summary>
 /// Gets the value of the Top attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <returns>The control's top coordinate.</returns>
 public static double GetTop(PerspexObject element)
 {
     return(element.GetValue(TopProperty));
 }
Example #39
0
 /// <summary>
 /// Sets the value of the Top attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <param name="value">The top value.</param>
 public static void SetTop(PerspexObject element, double value)
 {
     element.SetValue(TopProperty, value);
 }
Example #40
0
 public TargetBindingEndpoint(PerspexObject obj, PerspexProperty property)
 {
     Object = obj;
     Property = property;
 }
Example #41
0
        private static Vector ValidateOffset(PerspexObject o, Vector value)
        {
            ScrollViewer scrollViewer = o as ScrollViewer;

            if (scrollViewer != null)
            {
                var extent = scrollViewer.Extent;
                var viewport = scrollViewer.Viewport;
                return CoerceOffset(extent, viewport, value);
            }
            else
            {
                return value;
            }
        }
Example #42
0
 public static int GetRow(PerspexObject element)
 {
     return(element.GetValue(RowProperty));
 }
Example #43
0
 private static int ValidateCaretIndex(PerspexObject o, int value)
 {
     var text = o.GetValue(TextProperty);
     var length = (text != null) ? text.Length : 0;
     return Math.Max(0, Math.Min(length, value));
 }
Example #44
0
 /// <summary>
 /// Gets the value of the Top attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <returns>The control's top coordinate.</returns>
 public static double GetTop(PerspexObject element)
 {
     return element.GetValue(TopProperty);
 }
Example #45
0
 public IEnumerable<XamlBinding> GetBindings(PerspexObject source)
 {
     return from binding in this.bindings
         where binding.Target == source
         select binding;
 }
Example #46
0
 /// <summary>
 /// Gets the value of the RowSpan attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <returns>The control's row span.</returns>
 public static int GetRowSpan(PerspexObject element)
 {
     return element.GetValue(RowSpanProperty);
 }
Example #47
0
 public static void SetColumn(PerspexObject element, int value)
 {
     element.SetValue(ColumnProperty, value);
 }
Example #48
0
 /// <summary>
 /// Sets the value of the RowSpan attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <param name="value">The row span value.</param>
 public static void SetRowSpan(PerspexObject element, int value)
 {
     element.SetValue(RowSpanProperty, value);
 }
Example #49
0
 public static int GetColumnSpan(PerspexObject element)
 {
     return(element.GetValue(ColumnSpanProperty));
 }
Example #50
0
 /// <summary>
 /// Sets the value of the Left attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <param name="value">The left value.</param>
 public static void SetLeft(PerspexObject element, double value)
 {
     element.SetValue(LeftProperty, value);
 }
Example #51
0
 public TargetBindingEndpoint(PerspexObject obj, PerspexProperty property)
 {
     Object   = obj;
     Property = property;
 }
        /// <summary>
        /// Provides coercion for the <see cref="SelectedIndex"/> property.
        /// </summary>
        /// <param name="o">The object on which the property has changed.</param>
        /// <param name="value">The proposed value.</param>
        /// <returns>The coerced value.</returns>
        private static int CoerceSelectedIndex(PerspexObject o, int value)
        {
            var control = o as SelectingItemsControl;

            if (control != null)
            {
                if (value < -1)
                {
                    return -1;
                }
                else if (value > -1)
                {
                    var items = control.Items;

                    if (items != null)
                    {
                        var count = items.Count();
                        return Math.Min(value, count - 1);
                    }
                    else
                    {
                        return -1;
                    }
                }
            }

            return value;
        }
Example #53
0
 /// <summary>
 /// Gets the value of the Column attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <returns>The control's column.</returns>
 public static int GetColumn(PerspexObject element)
 {
     return element.GetValue(ColumnProperty);
 }
        /// <summary>
        /// Provides coercion for the <see cref="SelectedItem"/> property.
        /// </summary>
        /// <param name="o">The object on which the property has changed.</param>
        /// <param name="value">The proposed value.</param>
        /// <returns>The coerced value.</returns>
        private static object CoerceSelectedItem(PerspexObject o, object value)
        {
            var control = o as SelectingItemsControl;

            if (control != null)
            {
                if (value != null && (control.Items == null || control.Items.IndexOf(value) == -1))
                {
                    return null;
                }
            }

            return value;
        }
Example #55
0
 /// <summary>
 /// Sets the value of the Column attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <param name="value">The column value.</param>
 public static void SetColumn(PerspexObject element, int value)
 {
     element.SetValue(ColumnProperty, value);
 }
        /// <summary>
        /// Gets all <see cref="PerspexProperty"/>s registered on a object.
        /// </summary>
        /// <param name="o">The object.</param>
        /// <returns>A collection of <see cref="PerspexProperty"/> definitions.</returns>
        public IEnumerable<PerspexProperty> GetRegistered(PerspexObject o)
        {
            Contract.Requires<ArgumentNullException>(o != null);

            return GetRegistered(o.GetType());
        }
Example #57
0
        private static int ValidateRow(PerspexObject o, int value)
        {
            if (value < 0)
            {
                throw new ArgumentException("Invalid Grid.Row value.");
            }

            return value;
        }
Example #58
0
        public void GetProperties_Returns_Registered_Properties_For_Base_Types()
        {
            string[] names = PerspexObject.GetProperties(typeof(Class2)).Select(x => x.Name).ToArray();

            CollectionAssert.AreEqual(new[] { "Bar", "Foo", "Baz", "Qux" }, names);
        }
Example #59
0
 /// <summary>
 /// Gets the value of the Right attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <returns>The control's right coordinate.</returns>
 public static double GetRight(PerspexObject element)
 {
     return(element.GetValue(RightProperty));
 }
Example #60
0
 /// <summary>
 /// Sets the value of the Top attached property for a control.
 /// </summary>
 /// <param name="element">The control.</param>
 /// <param name="value">The top value.</param>
 public static void SetTop(PerspexObject element, double value)
 {
     element.SetValue(TopProperty, value);
 }