public override Type?GetChildDataContextType(Type dataContext, DataContextStack controlContextStack, DotvvmBindableObject control, DotvvmProperty?property = null) { var controlType = control.GetType(); var controlPropertyField = controlType.GetField($"{PropertyName}Property", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); var controlProperty = (DotvvmProperty?)controlPropertyField?.GetValue(null); if (controlProperty == null) { throw new Exception($"The property '{PropertyName}' was not found on control '{controlType}'!"); } if (control.properties.Contains(controlProperty)) { return(control.GetValueBinding(controlProperty) is IValueBinding valueBinding ? valueBinding.ResultType : dataContext); } if (AllowMissingProperty) { return(dataContext); } throw new Exception($"Property '{PropertyName}' is required on '{controlType.Name}'."); }
public static void CopyProperty(DotvvmBindableObject source, DotvvmProperty sourceProperty, DotvvmBindableObject target, DotvvmProperty targetProperty) { var binding = source.GetValueBinding(sourceProperty); if (binding != null) { target.SetBinding(targetProperty, binding); } else { target.SetValue(targetProperty, source.GetValue(sourceProperty)); } }
public override Type GetChildDataContextType(Type dataContext, DataContextStack controlContextStack, DotvvmBindableObject control, DotvvmProperty property = null) { var controlType = control.GetType(); var controlPropertyField = controlType.GetField($"{PropertyName}Property", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); var controlProperty = (DotvvmProperty)controlPropertyField?.GetValue(null); if (controlProperty == null) { throw new Exception($"The property '{PropertyName}' was not found on control '{controlType}'!"); } if (control.Properties.ContainsKey(controlProperty) && control.HasValueBinding(controlProperty)) { return(control.GetValueBinding(controlProperty).ResultType); } return(controlProperty.PropertyType); }
/// <summary> /// Processes the control tree. /// </summary> private void ProcessControlTreeCore(DotvvmBindableObject control, Action <DotvvmBindableObject> action) { // if there is a DataContext binding, locate the correct token var hasDataContext = false; var pathValue = control.GetValue(Internal.PathFragmentProperty, false); if (pathValue != null) { CurrentPath.Push(pathValue as string); RefreshCurrentPathArray(); hasDataContext = true; } else { var binding = control.GetValueBinding(DotvvmBindableObject.DataContextProperty, false); if (binding != null) { CurrentPath.Push(binding.GetKnockoutBindingExpression()); RefreshCurrentPathArray(); hasDataContext = true; } } action(control); // go through all children foreach (var child in control.GetLogicalChildren()) { ProcessControlTreeCore(child, action); } if (hasDataContext) { CurrentPath.Pop(); RefreshCurrentPathArray(); } }
/// <summary> /// Processes the control tree. /// </summary> private void ProcessControlTreeCore(DotvvmBindableObject control, Action<DotvvmBindableObject> action) { // if there is a DataContext binding, locate the correct token var hasDataContext = false; var pathValue = control.GetValue(Internal.PathFragmentProperty, false); if (pathValue != null) { CurrentPath.Push(pathValue as string); RefreshCurrentPathArray(); hasDataContext = true; } else { var binding = control.GetValueBinding(DotvvmBindableObject.DataContextProperty, false); if (binding != null) { CurrentPath.Push(binding.GetKnockoutBindingExpression()); RefreshCurrentPathArray(); hasDataContext = true; } } action(control); // go through all children foreach (var child in control.GetLogicalChildren()) { ProcessControlTreeCore(child, action); } if (hasDataContext) { CurrentPath.Pop(); RefreshCurrentPathArray(); } }
public IValueBinding GetValueBinding(string key) => control.GetValueBinding(group.GetDotvvmProperty(key));
public static DataContextStack GetItemDataContextStack(this DotvvmBindableObject bindableObject, DotvvmProperty dataSourceProperty) { return(bindableObject.GetValueBinding(dataSourceProperty) ?.GetProperty <CollectionElementDataContextBindingProperty>()?.DataContext); }