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))); }
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); } }
/// <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); }
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; }
/// <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))); }
public void SetStringProperty <TValue>(Expression <Func <TWrapper, TValue> > propertyName, string value, Func <string, object> convertAction = null) { SetStringProperty(ToolkitExtensions.GetMemberName(propertyName), value, convertAction); }
public void SetBoolProperty <TValue>(Expression <Func <TWrapper, TValue> > propertyName, string value) { SetBoolProperty(ToolkitExtensions.GetMemberName(propertyName), value); }
public void SetBinding <TValue>(Expression <Func <TWrapper, TValue> > propertyName, string value, bool required) { SetBinding(ToolkitExtensions.GetMemberName(propertyName), value, required); }
protected static string GetPropertyName <T>(Expression <Func <T, object> > expression) { return(ToolkitExtensions.GetMemberName(expression)); }