public static Task EnableValidationAsync <T, TValue>([NotNull] this T validatableViewModel,
                                                      [NotNull] Expression <Func <T, TValue> > getMember)
     where T : IValidatorAggregator
 {
     Should.NotBeNull(validatableViewModel, "validatableViewModel");
     return(validatableViewModel.EnableValidationAsync(ToolkitExtensions.GetMemberName(getMember)));
 }
Exemplo n.º 2
0
        public void ProviderShouldTrackPropertyChanges()
        {
            IEntityStateManager manager = GetStateManager();
            var stateModel = GetModel();
            var snapshot   = manager.CreateSnapshot(stateModel);

            snapshot.HasChanges(stateModel, ToolkitExtensions.GetMemberName <EntityStateModel>(() => model => model.Guid)).ShouldBeFalse();
            snapshot.HasChanges(stateModel, ToolkitExtensions.GetMemberName <EntityStateModel>(() => model => model.String)).ShouldBeFalse();
            snapshot.HasChanges(stateModel, ToolkitExtensions.GetMemberName <EntityStateModel>(() => model => model.Int)).ShouldBeFalse();

            stateModel.Int    = int.MaxValue;
            stateModel.String = null;
            stateModel.Guid   = Guid.Empty;

            snapshot.HasChanges(stateModel, ToolkitExtensions.GetMemberName <EntityStateModel>(() => model => model.Guid)).ShouldBeTrue();
            snapshot.HasChanges(stateModel, ToolkitExtensions.GetMemberName <EntityStateModel>(() => model => model.String)).ShouldBeTrue();
            snapshot.HasChanges(stateModel, ToolkitExtensions.GetMemberName <EntityStateModel>(() => model => model.Int)).ShouldBeTrue();

            stateModel.Int    = IntValue;
            stateModel.String = StringValue;
            stateModel.Guid   = GuidValue;

            snapshot.HasChanges(stateModel, ToolkitExtensions.GetMemberName <EntityStateModel>(() => model => model.Guid)).ShouldBeFalse();
            snapshot.HasChanges(stateModel, ToolkitExtensions.GetMemberName <EntityStateModel>(() => model => model.String)).ShouldBeFalse();
            snapshot.HasChanges(stateModel, ToolkitExtensions.GetMemberName <EntityStateModel>(() => model => model.Int)).ShouldBeFalse();
        }
        private static void Register(IBindingMemberProvider memberProvider)
        {
            BindingBuilderExtensions.RegisterDefaultBindingMember <Entry>(() => t => t.Text);
            BindingBuilderExtensions.RegisterDefaultBindingMember <Label>(() => t => t.Text);
            BindingBuilderExtensions.RegisterDefaultBindingMember <Button>("Clicked");
            BindingBuilderExtensions.RegisterDefaultBindingMember <ToolbarItem>("Clicked");
            BindingBuilderExtensions.RegisterDefaultBindingMember <ListView>(() => c => c.ItemsSource);
            BindingBuilderExtensions.RegisterDefaultBindingMember <ProgressBar>(() => c => c.Progress);

            //Element
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <Element, object>(AttachedMemberConstants.Parent, GetParentValue, SetParentValue, ObserveParentMember));
            memberProvider.Register(typeof(Element), "BindingContext", BindingMemberProvider.BindingContextMember, true);

            //VisualElement
            var visibleMember = memberProvider.GetBindingMember(typeof(VisualElement),
                                                                ToolkitExtensions.GetMemberName <VisualElement>(() => element => element.IsVisible), true, false);

            if (visibleMember != null)
            {
                memberProvider.Register(typeof(VisualElement), "Visible", visibleMember, true);
                memberProvider.Register(AttachedBindingMember.CreateMember <VisualElement, bool>("Hidden",
                                                                                                 (info, element) => !element.IsVisible, (info, element, arg3) => element.IsVisible = !arg3,
                                                                                                 (info, element, arg3) => visibleMember.TryObserve(element, arg3)));
            }
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <VisualElement, object>(AttachedMemberConstants.FindByNameMethod, FindByNameMemberImpl));

            memberProvider.Register(AttachedBindingMember.CreateMember <VisualElement, bool>(AttachedMemberConstants.Focused, (info, element) => element.IsFocused,
                                                                                             (info, element, arg3) =>
            {
                if (arg3)
                {
                    element.Focus();
                }
                else
                {
                    element.Unfocus();
                }
            }, (info, element, arg3) => BindingServiceProvider.WeakEventManager.Subscribe(element, "IsFocused", arg3)));

            var enabledMember = memberProvider.GetBindingMember(typeof(VisualElement),
                                                                ToolkitExtensions.GetMemberName <VisualElement>(() => element => element.IsEnabled), true, false);

            if (enabledMember != null)
            {
                memberProvider.Register(typeof(VisualElement), AttachedMemberConstants.Enabled, enabledMember, true);
            }

            //Toolbar item
            enabledMember = memberProvider.GetBindingMember(typeof(ToolbarItem), "IsEnabled", true, false);
            if (enabledMember != null)
            {
                memberProvider.Register(typeof(ToolbarItem), AttachedMemberConstants.Enabled, enabledMember, true);
            }
        }
 protected override void OnHandleAsyncValidationMessage(object sender, AsyncValidationMessage message)
 {
     if (!string.IsNullOrEmpty(message.PropertyName) && ToolkitExtensions.GetMemberName(Entity, () => model => model.Login) != message.PropertyName)
     {
         return;
     }
     Interlocked.Increment(ref _validationLoginCount);
     message.Task.TryExecuteSynchronously(task =>
     {
         Interlocked.Decrement(ref _validationLoginCount);
         this.OnPropertyChanged(() => m => m.IsLoginValidating);
     });
     this.OnPropertyChanged(() => m => m.IsLoginValidating);
 }
        private static void Register(IBindingMemberProvider memberProvider)
        {
            //Element
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <Element, object>(AttachedMemberConstants.Parent, GetParentValue, null, ObserveParentMember));
            memberProvider.Register(typeof(Element), "BindingContext", BindingMemberProvider.BindingContextMember, true);

            //VisualElement
            var visibleMember = memberProvider.GetBindingMember(typeof(VisualElement),
                                                                ToolkitExtensions.GetMemberName <VisualElement>(element => element.IsVisible), true, false);

            if (visibleMember != null)
            {
                memberProvider.Register(typeof(VisualElement), "Visible", visibleMember, true);
                memberProvider.Register(AttachedBindingMember.CreateMember <VisualElement, bool>("Hidden",
                                                                                                 (info, element) => !element.IsVisible, (info, element, arg3) => element.IsVisible = !arg3,
                                                                                                 (info, element, arg3) => visibleMember.TryObserve(element, arg3)));
            }
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <VisualElement, object>(AttachedMemberConstants.FindByNameMethod, FindByNameMemberImpl));

            memberProvider.Register(AttachedBindingMember.CreateMember <VisualElement, bool>(AttachedMemberConstants.Focused, (info, element) => element.IsFocused,
                                                                                             (info, element, arg3) =>
            {
                if (arg3)
                {
                    element.Focus();
                }
                else
                {
                    element.Unfocus();
                }
            }, (info, element, arg3) => BindingServiceProvider.WeakEventManager.Subscribe(element, "IsFocused", arg3)));

            var enabledMember = memberProvider.GetBindingMember(typeof(VisualElement),
                                                                ToolkitExtensions.GetMemberName <VisualElement>(element => element.IsEnabled), true, false);

            if (enabledMember != null)
            {
                memberProvider.Register(typeof(VisualElement), AttachedMemberConstants.Enabled, enabledMember, true);
            }

            //Toolbar item
            enabledMember = memberProvider.GetBindingMember(typeof(ToolbarItem), "IsEnabled", true, false);
            if (enabledMember != null)
            {
                memberProvider.Register(typeof(ToolbarItem), AttachedMemberConstants.Enabled, enabledMember, true);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 ///     Occurs when processing an asynchronous validation message.
 /// </summary>
 /// <param name="sender">The object that raised the event.</param>
 /// <param name="message">Information about event.</param>
 protected override void OnHandleAsyncValidationMessage(object sender, AsyncValidationMessage message)
 {
     if (ToolkitExtensions.GetMemberName(Entity, model => model.Login) != message.PropertyName)
     {
         return;
     }
     if (message.IsEndOperation)
     {
         Interlocked.Decrement(ref _validationLoginCount);
     }
     else
     {
         Interlocked.Increment(ref _validationLoginCount);
     }
     OnPropertyChanged(() => IsLoginValidating);
 }
Exemplo n.º 7
0
        static XamarinFormsBootstrapperBase()
        {
            MvvmApplication.SetDefaultDesignTimeManager();
            if (Device.OS != TargetPlatform.WinPhone)
            {
                LinkerInclude.Initialize();
            }
            DynamicMultiViewModelPresenter.CanShowViewModelDefault      = CanShowViewModelTabPresenter;
            DynamicViewModelNavigationPresenter.CanShowViewModelDefault = CanShowViewModelNavigationPresenter;
            ViewManager.ViewCleared     += OnViewCleared;
            ViewManager.ClearDataContext = true;
            var contextName = ToolkitExtensions.GetMemberName <BindableObject>(() => e => e.BindingContext);

            BindingServiceProvider.DataContextMemberAliases.Add(contextName);
            BindingServiceProvider.BindingMemberPriorities[contextName] = BindingServiceProvider.DataContextMemberPriority;
        }
Exemplo n.º 8
0
 /// <summary>
 ///     Sets errors for a property
 /// </summary>
 /// <param name="propertyExpresssion">The expression for the property</param>
 /// <param name="errors">The collection of errors</param>
 public void SetErrors <TValue>(Expression <Func <T, TValue> > propertyExpresssion, params object[] errors)
 {
     UpdateErrors(ToolkitExtensions.GetMemberName(propertyExpresssion), errors, false);
 }
 protected Task ValidateAsync <T>(Expression <Func <T> > getProperty)
 {
     Should.NotBeNull(getProperty, "getProperty");
     return(ValidateAsync(ToolkitExtensions.GetMemberName(getProperty)));
 }
Exemplo n.º 10
0
 public void SetStringProperty <TValue>(Expression <Func <TWrapper, TValue> > propertyName, string value, Func <string, object> convertAction = null)
 {
     SetStringProperty(ToolkitExtensions.GetMemberName(propertyName), value, convertAction);
 }
Exemplo n.º 11
0
 public void SetBoolProperty <TValue>(Expression <Func <TWrapper, TValue> > propertyName, string value)
 {
     SetBoolProperty(ToolkitExtensions.GetMemberName(propertyName), value);
 }
Exemplo n.º 12
0
 public void SetBinding <TValue>(Expression <Func <TWrapper, TValue> > propertyName, string value, bool required)
 {
     SetBinding(ToolkitExtensions.GetMemberName(propertyName), value, required);
 }
Exemplo n.º 13
0
 protected static string GetPropertyName <T>(Expression <Func <T, object> > expression)
 {
     return(ToolkitExtensions.GetMemberName(expression));
 }