/// <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(); } } } }
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))); }
/// <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); }
private static int ValidateRow(PerspexObject o, int value) { if (value < 0) { throw new ArgumentException("Invalid Grid.Row value."); } return(value); }
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); }
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; }
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); } }
/// <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); }
/// <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; }
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); } }
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); } }
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); }
/// <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(); } } } }
/// <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")); } }
public static void SetRowSpan(PerspexObject element, int value) { element.SetValue(RowSpanProperty, value); }
public XamlBinding GetBinding(PerspexObject po, PerspexProperty pp) { return this.bindings.First(xamlBinding => xamlBinding.Target == po && xamlBinding.TargetProperty == pp); }
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); }
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; } }
/// <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); }
/// <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); }
/// <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)); }
/// <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); }
public static void SetHotKey(PerspexObject target, KeyGesture value) => target.SetValue(HotKeyProperty, value);
/// <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); }
public static KeyGesture GetHotKey(PerspexObject target) => target.GetValue(HotKeyProperty);
public BindingTarget(PerspexObject @object, PerspexProperty property) { _obj = @object; _property = property; }
/// <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); }
private static int Coerce(PerspexObject instance, int value) { return(Math.Min(Math.Max(value, 0), ((Class1)instance).MaxQux)); }
/// <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)); }
/// <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); }
public TargetBindingEndpoint(PerspexObject obj, PerspexProperty property) { Object = obj; Property = property; }
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; } }
public static int GetRow(PerspexObject element) { return(element.GetValue(RowProperty)); }
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)); }
/// <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); }
public IEnumerable<XamlBinding> GetBindings(PerspexObject source) { return from binding in this.bindings where binding.Target == source select binding; }
/// <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); }
public static void SetColumn(PerspexObject element, int value) { element.SetValue(ColumnProperty, value); }
/// <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); }
public static int GetColumnSpan(PerspexObject element) { return(element.GetValue(ColumnSpanProperty)); }
/// <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; }
/// <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; }
/// <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()); }
private static int ValidateRow(PerspexObject o, int value) { if (value < 0) { throw new ArgumentException("Invalid Grid.Row value."); } return value; }
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); }
/// <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)); }