Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Selection Change to RadioGroup #224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions MonoTouch.Dialog/Elements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2459,12 +2459,21 @@ public Group (string key)
/// Captures the information about mutually exclusive elements in a RootElement
/// </summary>
public class RadioGroup : Group {

public Action<int> SelectionChanged { get; set;}
int selected;
public virtual int Selected {
get { return selected; }
set { selected = value; }
set {
if (value != selected) {
selected = value;
if (SelectionChanged != null)
SelectionChanged (selected);
}

}
}

public RadioGroup (string key, int selected) : base (key)
{
this.selected = selected;
Expand Down
23 changes: 15 additions & 8 deletions Sample/DemoElementApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,34 @@ RootElement CreateRoot ()

RootElement CreateSoundSection ()
{
return new RootElement ("Sounds"){
return new RootElement ("Sounds") {
new Section ("Silent") {
new BooleanElement ("Vibrate", true),
},
new Section ("Ring") {
new BooleanElement ("Vibrate", true),
new FloatElement (null, null, 0.8f),
new RootElement ("Ringtone", new RadioGroup (0)){
new Section ("Custom"){
new RootElement ("Ringtone", new RadioGroup (0) {
SelectionChanged =
new Action<int> ((int obj) => {
using (var msg = new UIAlertView ("RadioGroup",string.Format("you selected : {0}", obj), null, "Ok")){
msg.Show ();
}
})
}) {
new Section ("Custom") {
new RadioElement ("Circus Music"),
new RadioElement ("True Blood"),
},
new Section ("Standard"){
new Section ("Standard") {
from n in "Marimba,Alarm,Ascending,Bark,Xylophone".Split (',')
select (Element) new RadioElement (n)
select (Element)new RadioElement (n)
}
},
new RootElement ("New Text Message", new RadioGroup (3)){
new Section (){
new RootElement ("New Text Message", new RadioGroup (3)) {
new Section () {
from n in "None,Tri-tone,Chime,Glass,Horn,Bell,Eletronic".Split (',')
select (Element) new RadioElement (n)
select (Element)new RadioElement (n)
}
},
new BooleanElement ("New Voice Mail", false),
Expand Down