Created
June 24, 2011 00:17
-
-
Save TravisTheTechie/1043951 to your computer and use it in GitHub Desktop.
MonoMobile test
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using MonoTouch.Foundation; | |
using MonoTouch.UIKit; | |
using MonoMobile.MVVM; | |
using System.Collections.ObjectModel; | |
namespace MVVMExample | |
{ | |
public class Application : MonoMobileApplication | |
{ | |
public static new void Main (string[] args) | |
{ | |
Run ("Sample", typeof(NotesView), args); | |
} | |
} | |
public class NotesView : View | |
{ | |
protected new NotesViewModel DataContext { get { return (NotesViewModel)GetDataContext(); } } | |
public NotesView () | |
{ | |
} | |
[List(ViewType = typeof(NoteItemView))] | |
public ObservableCollection<NoteItem> Notes { get { return DataContext.Notes;} } | |
[NavbarButton("+")] | |
public void AddNote() | |
{ | |
Notes.Add(new NoteItem { Name = "Default"}); | |
} | |
public override void Initialize() | |
{ | |
base.DataContext = new NotesViewModel(); | |
} | |
} | |
public class NotesViewModel : ViewModel | |
{ | |
public NotesViewModel () | |
{ | |
var dataModel = new NotesDataModel (); | |
Notes = new ObservableCollection<NoteItem> (); | |
foreach (var item in dataModel.Load ()) | |
Notes.Add (item); | |
} | |
public ObservableCollection<NoteItem> Notes | |
{ | |
get { return Get(()=>Notes); } | |
set { Set(()=>Notes, value); } | |
} | |
} | |
public class NoteItem : ViewModel | |
{ | |
public string Name { | |
get { return Get (() => Name); } | |
set { Set (() => Name, value); } | |
} | |
public string Text { | |
get { return Get (() => Text); } | |
set { Set (() => Text, value); } | |
} | |
public override string ToString () | |
{ | |
return Name; | |
} | |
} | |
public class NoteItemView : View | |
{ | |
[Section] | |
[Entry] | |
public string Name { get; set; } | |
[Section("Note")] | |
[Entry] | |
[Multiline] | |
[Caption("")] | |
public string Text { get; set; } | |
} | |
public class NotesDataModel | |
{ | |
public IEnumerable<NoteItem> Load () | |
{ | |
return new List<NoteItem> { | |
new NoteItem { Name = "One" }, | |
new NoteItem { Name = "Two" }, | |
new NoteItem { Name = "Three" }, | |
new NoteItem { Name = "Four" }, | |
new NoteItem { Name = "Five" }, | |
new NoteItem { Name = "Six" }, | |
new NoteItem { Name = "Seven" }, | |
/* new NoteViewModel { Name = "Eight" }, | |
new NoteViewModel { Name = "Nine" }, | |
new NoteViewModel { Name = "Ten" }, | |
new NoteViewModel { Name = "Eleven" }, | |
new NoteViewModel { Name = "Dozen" } */ | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment