internal object GetValue(string key, ContextualObject current, View view, string typedKey) { try { //Check the local context var value = current == this ? LocalContext(false)?.GetValueInternal(key) : null;; if (value != null) { return(value); } //Check the cascading context if (value == null) { value = Context(false)?.GetValueInternal(typedKey) ?? Context(false)?.GetValueInternal(key); } //Check the parent if (value == null) { //If no more parents, check the environment if (view == null) { return(View.Environment.GetValueInternal(typedKey) ?? View.Environment.GetValueInternal(key)); } value = view.GetValue(key, current, view.Parent, typedKey); } return(value); } catch (Exception ex) { return(null); } }
public static Animation CreateAnimation <T>(T view, Easing easing, Action <T> action, Action completed = null, double duration = .2, double delay = 0, bool repeats = false, bool autoReverses = false, string id = null, Lerp lerp = null) where T : View { ContextualObject.MonitorChanges(); action(view); var changedProperties = ContextualObject.StopMonitoringChanges(); List <Animation> animations = null; if (changedProperties.Count == 0) { return(null); } if (changedProperties.Count > 1) { animations = new List <Animation>(); } foreach (var change in changedProperties) { var prop = change.Key; var values = change.Value; if (values.newValue == values.oldValue) { continue; } var animation = new Animation { Duration = duration, Easing = easing, Repeats = repeats, StartDelay = delay, StartValue = values.oldValue, EndValue = values.newValue, ContextualObject = prop.view, PropertyName = prop.property, Id = id, Lerp = lerp, }; if (autoReverses) { animation = animation.CreateAutoReversing(); } if (animations == null) { return(animation); } animations.Add(animation); } return(new Animation(animations) { Id = id, Duration = duration, Easing = easing, Repeats = repeats, }); }
internal T GetValue <T>(string key, ContextualObject current, View view, string typedKey, bool cascades) { try { var value = GetValue(key, current, view, typedKey, cascades); return((T)value); } catch (Exception ex) { return(default);
public override void Update(double percent) { try { base.Update(percent); var oldV = ContextualObject?.GetEnvironment(Parent.GetValueOfType <View>(), PropertyName, PropertyCascades); if (oldV is Binding b) { b.BindingValueChanged(null, PropertyName, CurrentValue); } else { ContextualObject?.SetEnvironment(PropertyName, CurrentValue, PropertyCascades); } } catch (Exception ex) { var message = $"Error lerping: {StartValue} to {EndValue} on {PropertyName}"; Debug.WriteLine(message); Logger.Error(ex, message); CurrentValue = EndValue; HasFinished = true; } }
public EnvironmentData(ContextualObject contextualObject) { View = contextualObject as View; }
public static string GetTypedKey(ContextualObject obj, string key) => GetTypedKey(obj.GetType(), key);