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.Iosui.Ios/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.ComponentModel;
11using System.Linq;
12#if __UNIFIED__
13using UIKit;
14#else
15using MonoTouch.UIKit;
16#endif
17using System;
18
19namespace Csla.Iosui.Binding
20{
24 public class BindingManager
25 {
29 private readonly UIView _view;
30
35 public BindingManager(UIView view)
36 {
37 _view = view;
38 Bindings = new List<Binding>();
39 }
40
44 public List<Binding> Bindings { get; private set; }
45
54 public void Add(UIView control, string targetProperty, object source, string sourceProperty, BindingDirection bindingDirection)
55 {
56 Add(new Binding(control, targetProperty, source, sourceProperty, bindingDirection));
57 }
58
63 public void Add(Binding binding)
64 {
65 Remove(binding.Target, binding.TargetProperty.Name, binding.Source, binding.SourceProperty.Name);
66 Bindings.Add(binding);
67 }
68
76 public void Remove(UIView target, string targetProperty, object source, string sourceProperty)
77 {
78 var binding = Bindings.FirstOrDefault(r => ReferenceEquals(r.Target, target) &&
79 r.TargetProperty.Name == targetProperty &&
80 ReferenceEquals(r.Source, source) &&
81 r.SourceProperty.Name == sourceProperty);
82 if (binding != null)
83 Remove(binding);
84 }
85
90 public void Remove(Binding binding)
91 {
92 binding.Dispose();
93 Bindings.Remove(binding);
94 }
95
99 public void RemoveAll()
100 {
101 for (var i = Bindings.Count - 1; i >= 0; i--)
102 {
103 Remove(Bindings[i]);
104 }
105 }
106
112 public IEnumerable<Binding> GetBindingsForView(UIView view)
113 {
114 return Bindings.Where(r => ReferenceEquals(r.Target.ViewForBaselineLayout, view));
115 }
116
121 public void UpdateSourceForView(UIView control)
122 {
123 foreach (var item in GetBindingsForView(control))
124 item.UpdateSource();
125 }
126
131 {
132 var view = _view.Subviews.FirstOrDefault(v => v.IsFirstResponder);
133 if (view != null)
135 }
136 }
137}
Contains an individual binding to tie a property on an Axml view to the property on a supplied object...
System.Reflection.PropertyInfo TargetProperty
The PropertyInfo for the property on the target view that is being bound to.
UIView Target
The iOS view that is used by the binding.
void Dispose()
Clears the bindings, references and event handlers.
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.
Provides the ability to bing properties on iOS UI controls to properties on CSLA objects.
void Remove(Binding binding)
Removes the supplied binding from the binding manager.
void UpdateSourceForView(UIView control)
Updates bindings with the current values in the supplied control.
void UpdateSourceForLastView()
Updates bindings on the view that is in current focus on the activity supplied to the BindingManager.
void Add(UIView control, string targetProperty, object source, string sourceProperty, BindingDirection bindingDirection)
Adds a new binding to be managed.
void RemoveAll()
Removes all bindings from the binding manager.
void Remove(UIView target, string targetProperty, object source, string sourceProperty)
Removes the binding matching the supplied parameters from the binding manager.
BindingManager(UIView view)
Creates a new instance of the binding manager.
IEnumerable< Binding > GetBindingsForView(UIView view)
Returns all bindings for the supplied view.
List< Binding > Bindings
A list of bindings that have been added to the manager.
void Add(Binding binding)
Adds a new binding to be managed.
string Name
Gets the property name value.