/// <summary> /// Updates the relative source value. /// </summary> public void UpdateSource([NotNull] object target) { if (target == null) { throw BindingExceptionManager.InvalidBindingTarget(RelativeSourceNode.Path); } var path = RelativeSourceNode.Path ?? String.Empty; if (!String.IsNullOrEmpty(Path)) { path = BindingExtensions.MergePath(path, Path); } if (RelativeSourceNode.Type != RelativeSourceExpressionNode.SelfType) { if (RelativeSourceNode.Type == RelativeSourceExpressionNode.MemberSourceType) { target = BindingServiceProvider.ContextManager.GetBindingContext(target); } else { target = new ParentSourceValue(target, RelativeSourceNode); } } IObserver observer = BindingServiceProvider.ObserverProvider.Observe(target, BindingPath.Create(path), false); _bindingSource = new BindingSource(observer); }
/// <summary> /// Initializes a new instance of the <see cref="BindingMemberInfo" /> class. /// </summary> public BindingMemberInfo([NotNull] string path, [NotNull] PropertyInfo property, Type sourceType) : this(path, BindingMemberType.Property, property.PropertyType) { _member = property; var method = property.GetGetMethod(true); if (method == null) { _getValueAccessorSingle = NotSupportedGetter; _canRead = false; } else { _getValueAccessorSingle = property.GetGetPropertyAccessor(method, path); _canRead = true; } method = property.GetSetMethod(true); if (method == null) { _setValueAccessorSingle = NotSupportedSetter; _canWrite = false; } else { _setValueAccessorSingleAction = property.GetSetPropertyAccessor(method, path); _canWrite = true; } _isSingleParameter = true; _memberEvent = BindingExtensions.TryFindMemberChangeEvent(BindingServiceProvider.MemberProvider, sourceType, property.Name); }
private object GetCommandParameter(IDataContext context) { var target = BindingTarget; if (target == null) { return(null); } var param = target.GetCommandParameter(context); var path = param as string; if (string.IsNullOrEmpty(path) || (!path.StartsWith("$args.", StringComparison.Ordinal) && !path.StartsWith("$arg.", StringComparison.Ordinal))) { return(param); } var args = context.GetData(BindingConstants.CurrentEventArgs); if (args == null) { return(null); } return(BindingExtensions.GetValueFromPath(args, path, 1)); }
public static object Convert(IBindingMemberInfo member, Type type, object value) { if (XamarinFormsToolkitExtensions.ValueConverter != null) { return(XamarinFormsToolkitExtensions.ValueConverter(member.Member as MemberInfo, type, value)); } if (value == null) { return(type.GetDefaultValue()); } if (type.IsInstanceOfType(value)) { return(value); } if (BindingExtensions.IsConvertible(value)) { return(System.Convert.ChangeType(value, type.GetNonNullableType(), BindingServiceProvider.BindingCultureInfo())); } if (type.GetTypeInfo().IsEnum) { var s = value as string; if (s != null) { return(Enum.Parse(type, s, false)); } return(Enum.ToObject(type, value)); } if (type == typeof(string)) { return(value.ToString()); } return(value); }
private static Action <IBindingBuilder>[] ConvertInternal(LambdaExpression expression, IBindingBuilder builder, bool ignoreCallback) { Expression lastExpression; string path; if (BindingExtensions.TryGetMemberPath(expression.Body, ".", false, out lastExpression, out path) && expression.Parameters[0] == lastExpression) { if (ignoreCallback) { builder.GetOrAddBindingSources().Add(context => BindingExtensions.CreateBindingSource(context, path, null)); return(Empty.Array <Action <IBindingBuilder> >()); } return(new Action <IBindingBuilder>[] { b => b.GetOrAddBindingSources().Add(context => BindingExtensions.CreateBindingSource(context, path, null)) }); } var visitor = new LambdaExpressionToBindingExpressionConverter(expression); visitor.ConvertInternal(expression); var actions = visitor._callbacks.ToArray(); visitor._members = null; visitor._sourceExpression = null; visitor._currentExpression = null; visitor._methodExpression = null; visitor._callbacks = null; return(actions); }
public object Get(string actionUrlMode, string encType, string charset, string method, string InputText, string Select) { InputText = HttpUtility.UrlDecode(InputText); Select = HttpUtility.UrlDecode(Select); string actionUrl = null; object parameters = new { actionUrlMode = actionUrlMode, encType = encType, charset = charset, method = method }; Uri newUri = BindingExtensions.BindTemplate(CommunicationContext.ApplicationBaseUri, new Template(Constants.FormSimplePath), parameters); if (actionUrlMode == "absolute") { actionUrl = newUri.AbsoluteUri; } else if (actionUrlMode == "relative") { actionUrl = newUri.AbsolutePath; } TestForm args = new TestForm(); args.InputText = InputText; args.Select = Select; args.ActionUrl = actionUrl; args.EncType = (encType == "multipart" ? (string)MediaType.MultipartFormData : (string)MediaType.ApplicationFormUrlEncoded); args.Charset = charset; args.Method = method; return(args); }
public MainMenuView() { this.fluentItem = this .AsFluent <Grid>() .Set(Control.BackgroundProperty, Theme.ThemeColors.Control.Normal) .Set(StackPanel.OrientationProperty, Orientation.Horizontal) .Set(Control.FontFamilyProperty, new FontFamily("SEGOE MDL2 assets")) .Set(Control.FontSizeProperty, 18d) .Set(FrameworkElement.HeightProperty, 80d) .DefaultCellSize("*", "*") .Cell(GridCellExtensions.Create() .Contains(new Button() .AsFluent() .Contains("\xE90B") .Bind(BindingExtensions .OneTime(ButtonBase.CommandProperty) .With(nameof(RootViewModel.OpenSearchViewCommand))))) .Cell(GridCellExtensions.Create() .Column(1) .Contains(new Button() .AsFluent() .Contains("\xE8D6") .Bind(BindingExtensions .OneTime(ButtonBase.CommandProperty) .With(nameof(RootViewModel.OpenPlayerViewCommand))))) .Cell(GridCellExtensions.Create() .Column(2) .Contains(new Button() .AsFluent() .Contains("\xE74F"))); }
private static LambdaExpression CreateLambdaExpression(Expression body, ParameterExpression[] parameterExpressions) { var types = new Type[parameterExpressions.Length + 1]; if (parameterExpressions.Length > 0) { var set = new HashSet <ParameterExpression>(); for (int index = 0; index < parameterExpressions.Length; ++index) { ParameterExpression parameterExpression = parameterExpressions[index]; types[index] = !parameterExpression.IsByRef ? parameterExpression.Type : parameterExpression.Type.MakeByRefType(); if (set.Contains(parameterExpression)) { throw BindingExtensions.DuplicateLambdaParameter(parameterExpression.ToString()); } set.Add(parameterExpression); } } types[parameterExpressions.Length] = body.Type; Type delegateType = Expression.GetDelegateType(types); return(CreateLambdaExpressionByType(delegateType, body, parameterExpressions)); }
public IDockDocument ShowDocument(string name, CreateDockDocumentDelegate createDockCallback) { IDockDocument doc = null; var avalonDoc = FindAvalonDocument(name); if (avalonDoc == null) { if (String.CompareOrdinal(name, "startPage") != 0 && StartPageDockDocument.GlobalAutoClose) { StartPageDockDocument.GlobalAutoClose = false; CloseDocument("startPage"); } avalonDoc = new DocumentContent() { Name = name }; doc = createDockCallback(avalonDoc, name); BindingExtensions.CreateBinding(doc, "DocumentTitle", avalonDoc, DocumentContent.TitleProperty, BindingMode.OneWay); avalonDoc.Content = doc; avalonDoc.Closing += AvalonDoc_Closing; avalonDoc.Closed += AvalonDoc_Closed; } avalonDoc.Show(dockingManager, false); Dispatcher.BeginInvoke(new NoArgsDelegate(() => { avalonDoc.Manager.ActiveDocument = avalonDoc; }), null); return(doc); }
/// <summary> /// Gets an instance of <see cref="IBindingMemberInfo" /> using the source type and binding path. /// </summary> /// <param name="sourceType">The specified source type.</param> /// <param name="path">The specified binding path.</param> /// <returns>The instance of <see cref="IBindingMemberInfo" />.</returns> protected override IBindingMemberInfo GetExplicitBindingMember(Type sourceType, string path) { if (typeof(DependencyObject).IsAssignableFrom(sourceType)) { var property = GetDependencyProperty(sourceType, path); if (property != null) { IBindingMemberInfo changeEvent = BindingExtensions.TryFindMemberChangeEvent(this, sourceType, path); #if WPF return(new DependencyPropertyBindingMember(property, path, property.PropertyType, property.ReadOnly, sourceType.GetProperty(path), changeEvent)); #else var member = sourceType.GetPropertyEx(path); Type type = typeof(object); bool readOnly = false; if (member != null) { type = member.PropertyType; readOnly = !member.CanWrite; } return(new DependencyPropertyBindingMember(property, path, type, readOnly, member, changeEvent)); #endif } } return(base.GetExplicitBindingMember(sourceType, path)); }
public BindingExtensionsTests() { _command = Substitute.For <ICommand>(); _commandGeneric = Substitute.For <ICommand <string> >(); _obj = new StubProducer(); BindingExtensions.Initialize(new MockBindingFactory()); }
private IExpressionNode GetResourceMember(IExpressionNode node, string memberName, IList <IExpressionNode> nodes) { IExpressionNode staticValue; if (_staticNodes.TryGetValue(node, out staticValue)) { return(staticValue); } IBindingPath path = BindingServiceProvider.BindingPathFactory(memberName); string firstMember = path.Parts[0]; Type type = BindingServiceProvider.ResourceResolver.ResolveType(firstMember, Context, false); var resourceMember = (ResourceExpressionNode)nodes[0]; if (resourceMember.Dynamic && type == null) { memberName = BindingExtensions.MergePath(path.Parts.Skip(1).ToArray()); return(GetOrAddBindingMember("$" + path.Path, (s, i) => new BindingMemberExpressionNode(firstMember, memberName, s, i))); } bool dynamicMember = false; IExpressionNode firstMemberNode = nodes[1]; if (!_staticNodes.TryGetValue(firstMemberNode, out staticValue)) { if (type == null) { var value = BindingServiceProvider .ResourceResolver .ResolveObject(firstMember, Context, true) .Value; var dynamicObject = value as IDynamicObject; if (dynamicObject == null || path.Parts.Count <= 1) { staticValue = new ConstantExpressionNode(value); } else { staticValue = new ConstantExpressionNode(dynamicObject.GetMember(path.Parts[1], Empty.Array <object>())); dynamicMember = true; } } else { staticValue = new ConstantExpressionNode(type, typeof(Type)); } _staticNodes[firstMemberNode] = staticValue; if (dynamicMember) { _staticNodes[nodes[2]] = staticValue; } } if (firstMemberNode == node || (dynamicMember && node == nodes[2])) { return(staticValue); } return(node); }
public static IFluentItem <T> SubDataContext <T>(this IFluentItem <T> fluentItem, string path) where T : FrameworkElement { fluentItem.Bind(BindingExtensions .OneWay(FrameworkElement.DataContextProperty) .With(path)); return(fluentItem); }
public static T Resource <T>(this IBindingSyntaxContext context, string name, Expression <Func <T> > member) { var value = BindingServiceProvider .ResourceResolver .ResolveObject(name, MugenMvvmToolkit.Models.DataContext.Empty, true) .Value; return((T)BindingExtensions.GetValueFromPath(value, member.GetMemberInfo().Name)); }
private void DataGridView1OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex].DataPropertyName.Contains(".")) { e.Value = BindingExtensions.GetValueFromPath( dataGridView1.Rows[e.RowIndex].DataBoundItem, dataGridView1.Columns[e.ColumnIndex].DataPropertyName); } }
/// <summary> /// Creates a new button. /// </summary> /// <param name="onClick">The OnClick of the button</param> /// <param name="icon">The icon for the button</param> /// <param name="text">The text of the button</param> /// <param name="gameObjectName">The name of the button's GameObject</param> /// <param name="tooltipText">The tooltip of the button</param> /// <param name="creationCallback">An action that is called with the button object when the button is created</param> public SingleButton(Action onClick, Sprite icon, string text, string gameObjectName, string tooltipText = "", Action <SingleButton> creationCallback = null) : base(UiManager.QMStateController.transform.Find("Container/Window/QMParent/Menu_Settings/Panel_QM_ScrollRect/Viewport/VerticalLayoutGroup/Buttons_UI_Elements_Row_1/Button_NameplateSettings").gameObject, icon, text, gameObjectName, tooltipText) { JumpBadge = rectTransform.Find("Badge_MMJump").gameObject; JumpBadge.SetActive(false); OnClick = onClick; BindingExtensions.Method_Public_Static_ButtonBindingHelper_Button_Action_0(ButtonComponent, new Action(() => OnClick?.Invoke())); creationCallback?.Invoke(this); }
public static object Convert(IBindingMemberInfo member, Type type, object value) #endif { if (value == null) { return(type.GetDefaultValue()); } if (type.IsInstanceOfType(value)) { return(value); } #if !WINDOWS_UWP && !NETFX_CORE #if XAMARIN_FORMS var converter = GetTypeConverter(type, member); #else var converter = GetTypeConverter(type, member.Member as MemberInfo); #endif if (converter != null && converter.CanConvertFrom(value.GetType())) { return(converter.ConvertFrom(value)); } #endif #if NETFX_CORE #if XAMARIN_FORMS if (ConvertibleTypes.Contains(value)) #else if (BindingExtensions.IsConvertible(value)) #endif #else if (value is IConvertible) #endif { return(System.Convert.ChangeType(value, type.GetNonNullableType(), BindingServiceProvider.BindingCultureInfo())); } #if WINDOWS_UWP || NETFX_CORE if (type.GetTypeInfo().IsEnum) #else if (type.IsEnum) #endif { #if WINDOWS_UWP || NETFX_CORE var s = value as string; if (s != null) { return(Enum.Parse(type, s, false)); } #endif return(Enum.ToObject(type, value)); } if (type == typeof(string)) { return(value.ToString()); } return(value); }
public IpMappingListViewItem(IpMappingItem item, HttpApiPage page) : base(item.Address) { this.Item = item; _page = page; this.SubItems.Add(new ListViewSubItem(this, item.Port)); this.SubItems.Add(new ListViewSubItem(this, BindingExtensions.GetAppName(item.AppId))); this.SubItems.Add(new ListViewSubItem(this, item.AppId)); this.SubItems.Add(new ListViewSubItem(this, item.Hash)); this.SubItems.Add(new ListViewSubItem(this, item.Store)); }
/// <summary> /// Initializes a new instance of the <see cref="BindingMemberInfo" /> class. /// </summary> public BindingMemberInfo([NotNull] string path, [NotNull] FieldInfo field, Type sourceType) : this(path, BindingMemberType.Field, field.FieldType) { _member = field; _getValueAccessorSingle = ServiceProvider.ReflectionManager.GetMemberGetter <object>(field); _setValueAccessorSingleAction = ServiceProvider.ReflectionManager.GetMemberSetter <object>(field); _canRead = true; _canWrite = true; _isSingleParameter = true; _memberEvent = BindingExtensions.TryFindMemberChangeEvent(BindingServiceProvider.MemberProvider, sourceType, field.Name); }
/// <summary> /// Initializes a new instance of the <see cref="ExpressionNode" /> class. /// </summary> public LambdaExpressionNode([NotNull] IExpressionNode expression, [CanBeNull] IEnumerable <string> parameters) : base(ExpressionNodeType.Lambda) { Should.NotBeNull(expression, "expression"); _expression = expression; _parameters = parameters == null ? Empty.Array <string>() : parameters.ToArray(); BindingExtensions.CheckDuplicateLambdaParameter(Parameters); }
private BindingMemberVisitor(BindingMemberVisitor innerVisitor, IEnumerable <string> lambdaParameters) : this() { _members = innerVisitor._members; _staticNodes = innerVisitor._staticNodes; if (innerVisitor._lamdaParameters != null) { _lamdaParameters.AddRange(innerVisitor._lamdaParameters); } _lamdaParameters.AddRange(lambdaParameters); BindingExtensions.CheckDuplicateLambdaParameter(_lamdaParameters); }
public PlayerView() { this.fluentItem = this.AsFluent <TabItem>() .Bind(BindingExtensions .OneTime(FrameworkElement.DataContextProperty) .With(nameof(RootViewModel.Player))) .Set(FrameworkElement.VisibilityProperty, Visibility.Collapsed) .Contains(new StackPanel() .AsFluent() .Stack(new Image() .AsFluent() .Margin(0, 25, 0, 0) .Size(300, 300) .Stretch(Stretch.UniformToFill) .Source(@"/Resources/Queen_Jazz.png")) .Stack(new Grid() .AsFluent() .Set(Control.BackgroundProperty, Theme.ThemeColors.Control.Normal) .Set(FrameworkElement.HeightProperty, 80d) .Cell(GridCellExtensions.Create() .Width("*") .Height("*") .Contains(new Button() .AsFluent() .Contains("⏮") .Set(Control.FontFamilyProperty, new FontFamily("Segoe UI symbol")))) .Set(Control.FontSizeProperty, 18d) .Cell(GridCellExtensions.Create() .Column(1) .Width("*") .Contains(new Button() .AsFluent() .Contains("▶") .Set(Control.FontFamilyProperty, new FontFamily("Segoe UI symbol")))) .Set(Control.FontSizeProperty, 18d) .Cell(GridCellExtensions.Create() .Width("*") .Column(2) .Contains(new Button() .AsFluent() .Contains("⏭") .Set(Control.FontFamilyProperty, new FontFamily("Segoe UI symbol")))) .Set(Control.FontSizeProperty, 18d) .Cell(GridCellExtensions.Create() .AutoHeight() .Row(1) .Span(1, 3) .Contains(new ProgressBar() .AsFluent() .Value(30) .Set(FrameworkElement.HeightProperty, 8d) .Set(Control.ForegroundProperty, Theme.ThemeColors.Control.Accent2))))); }
public IDockPane ShowPane(string name, CreateDockPaneDelegate createDockPane) { IDockPane pane = null; var avalonPane = FindAvalonPane(name); if (avalonPane == null) { avalonPane = new DockableContent() { Name = name }; pane = createDockPane(avalonPane, name); BindingExtensions.CreateBinding(pane, "PaneTitle", avalonPane, DockableContent.TitleProperty, BindingMode.OneWay); avalonPane.Content = pane; avalonPane.Closing += AvalonPane_Closing; avalonPane.Closed += AvalonPane_Closed; AnchorStyle anchor = AnchorStyle.None; switch (pane.DefaultPaneLocation) { case PaneLocation.Left: anchor = AnchorStyle.Left; break; case PaneLocation.Right: anchor = AnchorStyle.Right; break; case PaneLocation.Top: anchor = AnchorStyle.Top; break; case PaneLocation.Bottom: anchor = AnchorStyle.Bottom; break; } avalonPane.HideOnClose = pane.HidePaneOnClose; avalonPane.Show(dockingManager, anchor); } else { avalonPane.Show(); } Dispatcher.BeginInvoke(new NoArgsDelegate(() => { avalonPane.Manager.ActiveDocument = avalonPane; }), null); return(pane); }
private void Init() { if (_cachedViewModel == null) { _cachedViewModel = GetComponentInParent <VMBase>(); } _cachedViewModel.OnPropertyChanged += OnPropertyChanged; _cachedVMProperty = BindingExtensions.GetPropertyInfoOf <TPLD>(_cachedViewModel); _propertyChangeValidator = new PropertyChangeValidator(); }
private BindingMemberVisitor(BindingMemberVisitor innerVisitor, IEnumerable <string> lambdaParameters, IDataContext context) : this() { _ignoreLambda = true; _members = innerVisitor._members; _staticNodes = innerVisitor._staticNodes; if (innerVisitor._lamdaParameters != null) { _lamdaParameters.AddRange(innerVisitor._lamdaParameters); } _lamdaParameters.AddRange(lambdaParameters); Context = context; BindingExtensions.CheckDuplicateLambdaParameter(_lamdaParameters); }
public void ItSignalsMissingSessionWhenDecodingResponse() { // Example: for some odd reasons a web response is created outside of Ramone and we now try to decode it, // but without a session at hand. WebRequest request = WebRequest.Create(BindingExtensions.BindTemplate(BaseUrl, DossierTemplate, new { id = 8 })); using (WebResponse response = request.GetResponse()) { Response ramoneResponse = new Response((HttpWebResponse)response, null, 0); AssertThrows <ArgumentNullException>( () => ramoneResponse.Decode <ApplicationError>(), ex => ex.Message.Contains("session")); } }
public override Expression Visit(Expression node) { Expression lastExpression; string path; if (BindingExtensions.TryGetMemberPath(node, ".", false, out lastExpression, out path) && lastExpression != null) { if (lastExpression == _sourceExpression) { return(GetOrAddParameterExpression(string.Empty, path, node, BindingExtensions.CreteBindingSourceDel)); } return(TryGetExtensionExpressionOrDefault(lastExpression, node)); } return(TryGetExtensionExpressionOrDefault(lastExpression ?? node, node)); }
public bool TryHandle(object sender, object message) { var view = _view; if (!view.IsAlive()) { Update(null); return(false); } var activity = _view.Context.GetActivity(); if (activity == null) { Update(null); Tracer.Warn("(PopupMenu) The contex of view is not an activity."); return(false); } var templateId = (int)BindingServiceProvider .MemberProvider .GetBindingMember(_viewType, AttachedMemberNames.PopupMenuTemplate, false, true) .GetValue(_view, null); IBindingMemberInfo bindingMember = BindingServiceProvider .MemberProvider .GetBindingMember(_viewType, AttachedMemberNames.PlacementTargetPath, false, false); if (bindingMember != null) { var path = (string)bindingMember.GetValue(view, null); if (!string.IsNullOrEmpty(path)) { var itemView = (View)BindingExtensions.GetValueFromPath(message, path); if (itemView != null) { view = itemView; } } } var menu = new PopupMenu(activity, view); activity.MenuInflater.Inflate(templateId, menu.Menu, view); menu.SetOnDismissListener(DismissListener); menu.Show(); return(true); }
protected virtual void InitializeWhiteLabelRuntime() { // Init Bindings BindingExtensions.Initialize(new AppleBindingFactory()); // Init platform helpers Execute.Initialize(new IosMainThreadExecutor()); // Init dependencies var bootstrapper = CreateBootstrapper(); var container = bootstrapper.Initialize(); Dependencies.Initialize(container); // Notify dependencies ready to be used OnContainerInitialized(container); }
private void RefreshStylesAfterExternalEvent() { var panel = m_Parent.visualTree.elementPanel; if (panel == null) { return; } var updater = panel.GetUpdater(VisualTreeUpdatePhase.Bindings) as VisualTreeBindingsUpdater; if (updater == null) { return; } updater.PollElementsWithBindings((e, b) => BindingExtensions.HandleStyleUpdate(e)); }