Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Default Property binder for Android
- Loading branch information
1 parent
c849402
commit 7cc5cf0
Showing
4 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
ReactiveUI.Platforms/Android/AndroidDefaultPropertyBinding.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Linq; | ||
using ReactiveUI; | ||
using Android.Widget; | ||
|
||
namespace ReactiveUI.Android | ||
{ | ||
/// <summary> | ||
/// Default property bindings for common Android widgets | ||
/// </summary> | ||
public class AndroidDefaultPropertyBinding : IDefaultPropertyBindingProvider | ||
{ | ||
public Tuple<string, int> GetPropertyForControl(object control) | ||
{ | ||
// NB: These are intentionally arranged in priority order from most | ||
// specific to least specific. | ||
var items = new[] { | ||
new { Type = typeof(TextView), Property = "Text" }, | ||
new { Type = typeof(ImageView), Property = "Drawable" }, | ||
new { Type = typeof(ProgressBar), Property = "Progress" }, | ||
new { Type = typeof(CompoundButton), Property = "Checked" }, | ||
}; | ||
|
||
var type = control.GetType(); | ||
var kvp = items.FirstOrDefault(x => x.Type.IsAssignableFrom(type)); | ||
|
||
return kvp != null ? Tuple.Create(kvp.Property, 5) : null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters