protected virtual void SetupBindings() { _isConnectedBinding = this.SetBinding(() => DeviceVm.IsConnected).WhenSourceChanges(() => { System.Diagnostics.Debug.WriteLine("SubDeviceViewControllerBase: DeviceViewModel PropertyChanged IsConnected"); var navService = ServiceLocator.Current.GetInstance<INavigationService>(); if (!DeviceVm.IsConnected && navService.CurrentPageKey == _viewPageKey) { System.Diagnostics.Debug.WriteLine("Navigating back since device is not connected anymore."); navService.GoBack(); } }); _isConnectedBinding.ForceUpdateValueFromSourceToTarget(); _programModeBinding = this.SetBinding(() => DeviceVm.ProgramMode).WhenSourceChanges(() => { System.Diagnostics.Debug.WriteLine("SubDeviceViewControllerBase: DeviceViewModel PropertyChanged ProgramMode"); var navService = ServiceLocator.Current.GetInstance<INavigationService>(); if (_programMode != MoCoBusProgramMode.Invalid && DeviceVm.ProgramMode != _programMode && navService.CurrentPageKey == _viewPageKey) { System.Diagnostics.Debug.WriteLine("Navigating back since ProgramMode was changed to another mode"); navService.GoBack(); } }); _programModeBinding.ForceUpdateValueFromSourceToTarget(); }
public void SetCommand_OnBarButtonWithBinding_ParameterShouldUpdate() { var value = DateTime.Now.Ticks.ToString(); var vmSource = new TestViewModel { Model = new TestModel { MyProperty = value } }; var vmTarget = new TestViewModel(); var control = new UIBarButtonItemEx(); var binding = new Binding<string, string>( vmSource, () => vmSource.Model.MyProperty); control.SetCommand( "Clicked", vmTarget.SetPropertyCommand, binding); Assert.IsNull(vmTarget.TargetProperty); control.PerformEvent(); Assert.AreEqual(value, vmTarget.TargetProperty); value += "Test"; vmSource.Model.MyProperty = value; control.PerformEvent(); Assert.AreEqual(value, vmTarget.TargetProperty); }
public void Binding_Test1_Error() { Vm = new AccountViewModel(); #if ANDROID Operation = new EditText(Application.Context); ChildName = new EditText(Application.Context); #elif __IOS__ Operation = new UITextView(); ChildName = new UITextView(); #endif _binding1 = this.SetBinding( () => Vm.FormattedOperation, () => Operation.Text); _binding2 = this.SetBinding( () => Vm.AccountDetails.Name, () => ChildName.Text, fallbackValue: "Fallback", targetNullValue: "TargetNull"); Assert.AreEqual(AccountViewModel.EmptyText, Operation.Text); Assert.AreEqual(_binding2.FallbackValue, ChildName.Text); Vm.SetAccount(); Assert.AreEqual( AccountViewModel.NotEmptyText + Vm.AccountDetails.Balance + Vm.Amount, Operation.Text); Assert.AreEqual(Vm.AccountDetails.Name, ChildName.Text); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.AddComment); // Retrieve navigation parameter and set as current "DataContext" Vm = GlobalNavigation.GetAndRemoveParameter<FlowerViewModel>(Intent); // Avoid aggressive linker problem which removes the TextChanged event CommentText.TextChanged += (s, e) => { }; _saveBinding = this.SetBinding( () => CommentText.Text); // Avoid aggressive linker problem which removes the Click event SaveCommentButton.Click += (s, e) => { }; SaveCommentButton.SetCommand( "Click", Vm.SaveCommentCommand, _saveBinding); }
public void Binding_ConverterWithFallbackValue_ErrorInConverterShouldUseFallbackValue() { var vmSource = new TestViewModel { Model = new TestModel { MyProperty = "Initial value" } }; var vmTarget = new TestViewModel(); const string fallbackValue = "Fallback value"; const string targetNullValue = "Target null value"; _binding = new Binding<string, string>( vmSource, () => vmSource.Model.MyProperty, vmTarget, () => vmTarget.TargetProperty, BindingMode.Default, fallbackValue, targetNullValue) .ConvertSourceToTarget( value => { throw new InvalidCastException("Only for test"); }); Assert.AreEqual(fallbackValue, vmTarget.TargetProperty); vmSource.Model.MyProperty = "New value"; Assert.AreEqual(fallbackValue, vmTarget.TargetProperty); }
public void Binding_MultipleLevelsOfNull_ShouldUseFallbackValueThenTargetNullValue() { var vmSource = new TestViewModel(); var vmTarget = new TestViewModel(); const string fallbackValue = "Fallback value"; const string targetNullValue = "Target null value"; _binding = new Binding<string, string>( vmSource, () => vmSource.Nested.Model.MyProperty, vmTarget, () => vmTarget.TargetProperty, BindingMode.Default, fallbackValue, targetNullValue); Assert.AreEqual(fallbackValue, vmTarget.TargetProperty); vmSource.Nested = new TestViewModel(); Assert.AreEqual(fallbackValue, vmTarget.TargetProperty); vmSource.Nested.Model = new TestModel(); Assert.AreEqual(targetNullValue, vmTarget.TargetProperty); vmSource.Nested.Model.MyProperty = DateTime.Now.Ticks.ToString(); Assert.AreEqual(vmSource.Nested.Model.MyProperty, vmTarget.TargetProperty); }
public void Binding_TwoWayFromEditTextToEditTextWithObserveEvent_BindingGetsUpdated() { var control1 = new EditText(Application.Context); var control2 = new EditText(Application.Context); var binding = new Binding<string, string>( control1, () => control1.Text, control2, () => control2.Text, BindingMode.TwoWay) .ObserveSourceEvent<View.LongClickEventArgs>("LongClick") .ObserveTargetEvent<View.LongClickEventArgs>("LongClick"); Assert.AreEqual(string.Empty, control1.Text); Assert.AreEqual(control1.Text, control2.Text); var value = DateTime.Now.Ticks.ToString(); control1.Text = value; Assert.AreEqual(value, control1.Text); Assert.AreEqual(string.Empty, control2.Text); control1.PerformLongClick(); Assert.AreEqual(control1.Text, control2.Text); var newValue = value + "Suffix"; control2.Text = newValue; Assert.AreEqual(newValue, control2.Text); Assert.AreEqual(value, control1.Text); control2.PerformLongClick(); Assert.AreEqual(control2.Text, control1.Text); }
protected virtual void DetachBindings() { _isConnectedBinding?.Detach(); _isConnectedBinding = null; _programModeBinding?.Detach(); _programModeBinding = null; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Set bindings NameBinding = this.SetBinding(() => NoteViewModel.CurrentNote.Title, () => lblTitle.Text); DateBinding = this.SetBinding(() => NoteViewModel.CurrentNote.DateString, () => lblDate.Text); ContentBinding = this.SetBinding(() => NoteViewModel.CurrentNote.Content, () => lblContent.Text); }
public void SetViewModel (LogTimeEntriesViewModel viewModel) { ViewModel = viewModel; // TODO: investigate why WhenSourceChanges doesn't work. :( isRunningBinding = this.SetBinding (() => ViewModel.IsTimeEntryRunning, () => IsRunning); durationBinding = this.SetBinding (() => ViewModel.Duration, () => DurationTextView.Text); descBinding = this.SetBinding (() => ViewModel.Description, () => DescriptionTextView.Text) .ConvertSourceToTarget (desc => desc != string.Empty ? desc : activity.ApplicationContext.Resources.GetText (Resource.String.TimerComponentNoDescription)); projectBinding = this.SetBinding (() => ViewModel.ProjectName, () => ProjectTextView.Text) .ConvertSourceToTarget (proj => proj != string.Empty ? proj : activity.ApplicationContext.Resources.GetText (Resource.String.TimerComponentNoProject)); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it ButtonGet = FindViewById<Button>(Resource.Id.myButton); UsernameText = FindViewById<EditText>(Resource.Id.username); PasswordText = FindViewById<EditText>(Resource.Id.password); ComboText = FindViewById<TextView>(Resource.Id.combo); ProgressBar = FindViewById<ProgressBar>(Resource.Id.progressBar1); //So things don't link out. //Only needed if linking all //UsernameText.TextChanged += (sender, e) => {}; //PasswordText.TextChanged += (sender, e) => {}; //ButtonGet.Click += (sender, e) => {}; ButtonGet.SetCommand("Click", VM.GetPeopleCommand); unBind = this.SetBinding(() => VM.Username, () => UsernameText.Text, BindingMode.TwoWay); passBind = this.SetBinding(() => VM.Password, () => PasswordText.Text, BindingMode.TwoWay); combBind = this.SetBinding(() => VM.ComboDisplay, () => ComboText.Text, BindingMode.OneWay); busyBind = this.SetBinding(() => VM.IsBusy).WhenSourceChanges(() => { ButtonGet.Enabled = !VM.IsBusy; if(VM.IsBusy) ProgressBar.Visibility = ViewStates.Visible; else ProgressBar.Visibility = ViewStates.Invisible; }); updatedBind = this.SetBinding(() => VM.People) .WhenSourceChanges(() => { RunOnUiThread(() =>Toast.MakeText(this, "Count: " + VM.People.Count, ToastLength.Short).Show()); }); }
public AndroidNotificationManager () { ctx = ServiceContainer.Resolve<Context> (); notificationManager = (NotificationManager)ctx.GetSystemService (Context.NotificationService); runningBuilder = CreateRunningNotificationBuilder (ctx); idleBuilder = CreateIdleNotificationBuilder (ctx); propertyTracker = new PropertyChangeTracker (); TimeEntryManager = ServiceContainer.Resolve<ActiveTimeEntryManager> (); binding = this.SetBinding (() => TimeEntryManager.ActiveTimeEntry).WhenSourceChanges (OnActiveTimeEntryChanged); var bus = ServiceContainer.Resolve<MessageBus> (); subscriptionSettingChanged = bus.Subscribe<SettingChangedMessage> (OnSettingChanged); }
public override void ViewDidLoad() { View = new UniversalView(); base.ViewDidLoad(); InitializeComponent(); Title = "Add comment"; _commentBinding = this.SetBinding( () => CommentText.Text) .UpdateSourceTrigger("Changed"); SaveCommentButton.SetCommand("Clicked", Vm.SaveCommentCommand, _commentBinding); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); _messageBinding = this.SetBinding(() => EditMessage.Text, BindingMode.TwoWay); MessageButton.SetCommand("Click", Vm.MessageCommand, _messageBinding); _textViewBinding = this.SetBinding(() => Vm.PreviousMessage, () => PreviousMessage.Text); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it CommandButton.SetCommand("Click", ViewModel.ShowDialogCommand); _messageBinding = this.SetBinding(() => ViewModel.Message, () => MessageView.Text, BindingMode.OneWay); }
public async override void ViewDidLoad () { base.ViewDidLoad (); ViewModel = await NewProjectViewModel.Init (workspaceId); clientBinding = this.SetBinding (() => ViewModel.ClientName).WhenSourceChanges (() => { var name = string.IsNullOrEmpty (ViewModel.ClientName) ? "NewProjectClientHint".Tr () : ViewModel.ClientName; if (string.IsNullOrEmpty (ViewModel.ClientName)) { clientButton.Apply (Style.NewProject.ClientButton).Apply (Style.NewProject.NoClient); } else { clientButton.Apply (Style.NewProject.WithClient); } clientButton.SetTitle (name, UIControlState.Normal); }); }
protected override void OnCreateActivity (Bundle state) { base.OnCreateActivity (state); SetContentView (Resource.Layout.IntroLayout); FindViewById<TextView> (Resource.Id.IntroTitle).SetFont (Font.DINMedium); FindViewById<TextView> (Resource.Id.IntroLoginText).SetFont (Font.DINMedium); LoginButton = FindViewById<Button> (Resource.Id.LoginButton).SetFont (Font.DINMedium); StartNowButton = FindViewById<Button> (Resource.Id.StartNowButton).SetFont (Font.DINMedium); LoginButton.Click += LoginButtonClick; StartNowButton.Click += StartNowButtonClick; ViewModel = IntroViewModel.Init (); isAuthenticatedBinding = this.SetBinding (() => ViewModel.IsAuthenticated).WhenSourceChanges (StartAuth); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. Button.AccessibilityIdentifier = "myButton"; Button.SetCommand("TouchUpInside", VM.GetPeopleCommand); unBind = this.SetBinding(() => VM.Username, () => TextUsername.Text, BindingMode.TwoWay) .UpdateTargetTrigger("EditingChanged"); passBind = this.SetBinding(() => VM.Password, () => TextPassword.Text, BindingMode.TwoWay) .UpdateTargetTrigger("EditingChanged"); combBind = this.SetBinding(() => VM.ComboDisplay, () => LabelCombo.Text, BindingMode.OneWay); busyBind = this.SetBinding(() => VM.IsBusy).WhenSourceChanges(() => { Button.Enabled = !VM.IsBusy; if(VM.IsBusy) ProgressBar.StartAnimating(); else ProgressBar.StopAnimating(); }); updatedBind = this.SetBinding(() => VM.People) .WhenSourceChanges(() => { notificationView = new GCDiscreetNotificationView ( text: "There are " + VM.People.Count + " people", activity: false, presentationMode: GCDNPresentationMode.Bottom, view: View ); notificationView.ShowAndDismissAfter (1); }); }
private void BindViewHolder(CachingViewHolder holder, GalleryItem item, int position) { var layoutRoot = holder.ItemView; layoutRoot.Post(() => { var width = layoutRoot.Width; var layoutParams = layoutRoot.LayoutParameters; layoutParams.Height = width; layoutRoot.LayoutParameters = layoutParams; }); var thumbnailView = holder.FindCachedViewById<ImageViewAsync>(Resource.Id.Thumbnail); holder.DeleteBinding(thumbnailView); var thumbnailBinding = new Binding<string, string>(item, () => item.Thumbnail) .WhenSourceChanges(() => ImageService.Instance.LoadUrl(item.Thumbnail).Into(thumbnailView)); holder.SaveBinding(thumbnailView, thumbnailBinding); }
public override Dialog OnCreateDialog (Bundle savedInstanceState) { nameEditText = new EditText (Activity); nameEditText.SetHint (Resource.String.CreateTagDialogHint); nameEditText.InputType = InputTypes.TextFlagCapSentences; nameEditText.TextChanged += OnNameEditTextTextChanged; // Again we need to define binding inside OnCreateDialog tagBinding = this.SetBinding (() => viewModel.TagName, () => nameEditText.Text, BindingMode.TwoWay); return new AlertDialog.Builder (Activity) .SetTitle (Resource.String.CreateTagDialogTitle) .SetView (nameEditText) .SetPositiveButton (Resource.String.CreateTagDialogOk, OnPositiveButtonClicked) .Create (); }
public override void ViewDidLoad () { base.ViewDidLoad (); _nicknameLabelBinding = this.SetBinding ( () => Vm.Nickname, () => nickname.Text); _emailLabelBinding = this.SetBinding ( () => Vm.Email, () => email.Text); loginButton.TouchUpInside += async (sender, e) => { Auth0User user = null; try { user = await _auth0.LoginAsync (this, scope: "openid profile"); } catch (OperationCanceledException opEx) { Insights.Report (opEx); } if (user != null) { var emailAddress = user.Profile.GetValue ("email").ToString (); var nicknameValue = user.Profile.GetValue ("nickname").ToString (); Insights.Identify(emailAddress, null); Insights.Identify(null, Insights.Traits.Email, emailAddress); Insights.Identify(null, Insights.Traits.Name, nicknameValue); Vm.Nickname = nicknameValue; Vm.Email = emailAddress; _settingsService.UserIdToken = user.IdToken; _settingsService.EmailAddress = emailAddress; _settingsService.Nickname = nicknameValue; //AppDelegate.RegisterForRemoteNotifications(null); var pushSettings = UIUserNotificationSettings.GetSettingsForTypes ( UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, new NSSet ()); UIApplication.SharedApplication.RegisterUserNotificationSettings (pushSettings); UIApplication.SharedApplication.RegisterForRemoteNotifications (); Messenger.Default.Send(new UserLoggedInMessage()); } }; }
void SetBindings () { remoteBinding = this.SetBinding(() => _viewModel.IsRemote, _isRemote, () => _isRemote.Visibility, BindingMode.OneWay).ConvertSourceToTarget(Converters.BoolToVisibilityReverseConverter); bindings.Add(this.SetBinding(() => _viewModel.JobType, _type, () => _type.Text, BindingMode.OneWay)); bindings.Add(this.SetBinding(() => _viewModel.JobDescription, _description, () => _description.Text, BindingMode.OneWay)); bindings.Add(this.SetBinding(() => _viewModel.CompanyName, _companyName, () => _companyName.Text, BindingMode.OneWay)); bindings.Add(this.SetBinding(() => _viewModel.Location, _location, () => _location.Text, BindingMode.OneWay)); bindings.Add(this.SetBinding(() => _viewModel.Visits, _visitors, () => _visitors.Text, BindingMode.OneWay)); _sendCV.SetCommand ("Click", _viewModel.SendCVCommand); }
public void Binding_OneWayFromCheckBoxToCheckBoxWithUpdateTrigger_BindingGetsUpdated() { var control1 = new CheckBox(Application.Context); var control2 = new CheckBox(Application.Context); var binding = new Binding<bool, bool>( control1, () => control1.Checked, control2, () => control2.Checked); Assert.IsFalse(control1.Checked); Assert.IsFalse(control2.Checked); control1.Checked = true; Assert.IsTrue(control1.Checked); Assert.IsTrue(control2.Checked); }
public void Binding_OneWayFromCheckBoxToEditTextWithUpdateTrigger_BindingGetsUpdated() { var control1 = new UITextViewEx(); var control2 = new UISwitchEx(); var binding = new Binding<bool, string>( control2, () => control2.On, control1, () => control1.Text); Assert.AreEqual("False", control1.Text); Assert.IsFalse(control2.On); control2.On = true; Assert.AreEqual("True", control1.Text); Assert.IsTrue(control2.On); }
public void Binding_OneWayFromCheckBoxToCheckBoxWithUpdateTrigger_BindingGetsUpdated() { var control1 = new UISwitchEx(); var control2 = new UISwitchEx(); var binding = new Binding<bool, bool>( control1, () => control1.On, control2, () => control2.On); Assert.IsFalse(control1.On); Assert.IsFalse(control2.On); control1.On = true; Assert.IsTrue(control1.On); Assert.IsTrue(control2.On); }
public void Binding_OneWayFromCheckBoxToEditTextWithUpdateTrigger_BindingGetsUpdated() { var control1 = new EditText(Application.Context); var control2 = new CheckBox(Application.Context); var binding = new Binding<bool, string>( control2, () => control2.Checked, control1, () => control1.Text); Assert.AreEqual("False", control1.Text); Assert.IsFalse(control2.Checked); control2.Checked = true; Assert.AreEqual("True", control1.Text); Assert.IsTrue(control2.Checked); }
public void Binding_OneWayFromEditTextToCheckBoxWithUpdateTrigger_BindingGetsUpdated() { var control1 = new EditText(Application.Context); var control2 = new CheckBox(Application.Context); var binding = new Binding<string, bool>( control1, () => control1.Text, control2, () => control2.Checked); Assert.AreEqual(string.Empty, control1.Text); Assert.IsFalse(control2.Checked); var value = "True"; control1.Text = value; Assert.AreEqual(value, control1.Text); Assert.IsTrue(control2.Checked); }
public void Binding_OneWayFromCheckBoxToEditTextWithObserveEvent_BindingGetsUpdated() { var control1 = new EditText(Application.Context); var control2 = new CheckBox(Application.Context); var binding = new Binding<bool, string>( control2, () => control2.Checked, control1, () => control1.Text) .ObserveSourceEvent(); // LostFocus doesn't work programatically with CheckBoxes Assert.AreEqual("False", control1.Text); Assert.IsFalse(control2.Checked); control2.Checked = true; Assert.IsTrue(control2.Checked); Assert.AreEqual("True", control1.Text); }
public void Binding_OneWayFromEditTextToCheckBoxWithUpdateTrigger_BindingGetsUpdated() { var control1 = new UITextViewEx(); var control2 = new UISwitchEx(); var binding = new Binding<string, bool>( control1, () => control1.Text, control2, () => control2.On); Assert.AreEqual(string.Empty, control1.Text); Assert.IsFalse(control2.On); var value = "True"; control1.Text = value; Assert.AreEqual(value, control1.Text); Assert.IsTrue(control2.On); }
public void Binding_OneWayFromCheckBoxToCheckBoxWithUpdateTrigger_BindingGetsUpdated() { var control1 = new CheckBox(Application.Context); var control2 = new CheckBox(Application.Context); var binding = new Binding<bool, bool>( control1, () => control1.Checked, control2, () => control2.Checked) .UpdateSourceTrigger<CompoundButton.CheckedChangeEventArgs>("CheckedChange"); Assert.IsFalse(control1.Checked); Assert.IsFalse(control2.Checked); control1.Checked = true; Assert.IsTrue(control1.Checked); Assert.IsTrue(control2.Checked); }