CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
Csla.Axml.Android/Binding/BindingManager.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="BindingManager.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Provides the ability to bing properties on Axml controls to properties on CSLA objects. Bindinds update normally when the control looses focus</summary>
7//-----------------------------------------------------------------------
8
9using System.Collections.Generic;
10using System.Linq;
11
12using Android.App;
13using Android.Views;
14
15namespace Csla.Axml.Binding
16{
20 public class BindingManager
21 {
22 private readonly Activity _activity;
23
28 public BindingManager(Activity activity)
29 {
30 _activity = activity;
31 Bindings = new List<Binding>();
32 }
33
37 public List<Binding> Bindings { get; private set; }
38
46 public void Add(int viewId, string targetProperty, object source, string sourceProperty)
47 {
48 var target = _activity.FindViewById(viewId);
49 Add(target, targetProperty, source, sourceProperty);
50 }
51
59 public void Add(View target, string targetProperty, object source, string sourceProperty)
60 {
61 Add(new Binding(target, targetProperty, source, sourceProperty));
62 }
63
68 public void Add(Binding binding)
69 {
70 Remove(binding.Target, binding.TargetProperty.Name, binding.Source, binding.SourceProperty.Name);
71 Bindings.Add(binding);
72 }
73
81 public void Remove(View target, string targetProperty, object source, string sourceProperty)
82 {
83 var binding = Bindings.FirstOrDefault(r => ReferenceEquals(r.Target, target) &&
84 r.TargetProperty.Name == targetProperty &&
85 ReferenceEquals(r.Source, source) &&
86 r.SourceProperty.Name == sourceProperty);
87 if (binding != null)
88 Remove(binding);
89 }
90
95 public void Remove(Binding binding)
96 {
97 binding.Dispose();
98 Bindings.Remove(binding);
99 }
100
104 public void RemoveAll()
105 {
106 for (var i = Bindings.Count - 1; i >= 0; i--)
107 {
108 Remove(Bindings[i]);
109 }
110 }
111
117 public IEnumerable<Binding> GetBindingsForView(View view)
118 {
119 return Bindings.Where(r => ReferenceEquals(r.Target, view));
120 }
121
126 public void UpdateSourceForView(View view)
127 {
128 foreach (var item in GetBindingsForView(view))
129 item.UpdateSource();
130 }
131
136 {
137 var view = _activity.CurrentFocus;
138 if (view != null)
140 }
141 }
142}
Contains an individual binding to tie a property on an Axml view to the property on a supplied object...
object Source
The object that the view is bound to.
System.Reflection.PropertyInfo SourceProperty
The PropertyInfo for the property on the source object that is being bound to.
View Target
The Axml view that is used by the binding.
void Dispose()
Clears the bindings, references and event handlers.
System.Reflection.PropertyInfo TargetProperty
The PropertyInfo for the property on the target view that is being bound to.
Provides the ability to bing properties on Axml controls to properties on CSLA objects.
void Remove(View target, string targetProperty, object source, string sourceProperty)
Removes the binding matching the supplied parameters from the binding manager.
void Add(int viewId, string targetProperty, object source, string sourceProperty)
Adds a new binding to be managed.
void Remove(Binding binding)
Removes the supplied binding from the binding manager.
void UpdateSourceForView(View view)
Updates bindings with the current values in the supplied view.
void Add(Binding binding)
Adds a new binding to be managed.
void Add(View target, string targetProperty, object source, string sourceProperty)
Adds a new binding to be managed.
IEnumerable< Binding > GetBindingsForView(View view)
Returns all bindings for the supplied view.
void UpdateSourceForLastView()
Updates bindings on the view that is in current focus on the activity supplied to the BindingManager.
List< Binding > Bindings
A list of bindings that have been added to the manager.
void RemoveAll()
Removes all bindings from the binding manager.
BindingManager(Activity activity)
Creates a new instance of the binding manager.
string Name
Gets the property name value.