Created
June 24, 2011 00:49
-
-
Save RobertKozak/1044002 to your computer and use it in GitHub Desktop.
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
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(NoteView))] | |
public ObservableCollection<NoteItem> Notes { get { return DataContext.Notes; } } | |
[NavbarButton("+")] | |
public void AddNote() | |
{ | |
Notes.Add(new NoteItem{ Name = "Default"}); | |
//Alert.Show("Msg", "add!"); | |
//(DataContext as ObservableCollection<NoteViewModel>).Add(new NoteViewModel { Name = "Default" }); | |
} | |
public override void Initialize() | |
{ | |
base.DataContext = new NotesViewModel(); | |
} | |
} | |
public class NotesViewModel : ViewModel | |
{ | |
public ObservableCollection<NoteItem> Notes | |
{ | |
get { return Get(()=>Notes); } | |
set { Set(()=>Notes, value); } | |
} | |
public NotesViewModel() | |
{ | |
var dataModel = new NotesDataModel(); | |
Notes = new ObservableCollection<NoteItem>(); | |
foreach (var item in dataModel.Load()) | |
Notes.Add(item); | |
} | |
} | |
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 NoteView : 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 NoteItem { Name = "Eight" }, | |
new NoteItem { Name = "Nine" }, | |
new NoteItem { Name = "Ten" }, | |
new NoteItem { Name = "Eleven" }, | |
new NoteItem { Name = "Dozen" } */ | |
}; | |
} | |
} | |
// ignore me | |
public class BasicView : View | |
{ | |
public bool TestOnOff { get; set; } | |
[Caption("Why?")] | |
[Entry] | |
public string Why { get; set; } | |
[Section("Actions")] | |
[Button] | |
public void PressDown () | |
{ | |
} | |
[NavbarButton] | |
public void Plus () | |
{ | |
} | |
} | |
/* | |
public override void WillTerminate (UIApplication application) | |
{ | |
//Save data here | |
} | |
*/ | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment