コード例 #1
0
        public void ViewModelTestEditACard()
        {
            Group m = new Group();

            m.Setup();

            m.testMode = true;
            FlashCard card    = new FlashCard("Question", "Answer", "Test");
            FlashCard newCard = new FlashCard("que", "ans", "Test");

            m.Cards.Add(card);
            FlashCardsViewModel vm = new FlashCardsViewModel("Test", m.Cards, m);

            vm.EditFlashCard(card, newCard);
            bool found = false;

            foreach (FlashCard f in vm.AllCards)
            {
                if (f.ToString() == card.ToString())
                {
                    found = true;
                }
            }
            Assert.IsFalse(found); // this should be false
        }
コード例 #2
0
        public AddFlashCardPageViewModel(string cardGroup, FlashCardsViewModel flashCardsViewModel)
        {
            this.group = cardGroup;
            this.flashCardsViewModel = flashCardsViewModel;

            AddCommand = new Command(execute: AddNewCard);
        }
コード例 #3
0
        public EditFlashCardViewModel(FlashCard card, FlashCardsViewModel flashCardsViewModel)
        {
            this.oldFlashCard        = card;
            this.flashCardsViewModel = flashCardsViewModel;
            Question = card.Question;
            Answer   = card.Answer;

            SaveCommand = new Command(execute: SaveNewCard);
        }
コード例 #4
0
        public FlashCardsPage(FlashCardsViewModel vm)
        {
            InitializeComponent();
            this.vm        = vm;
            BindingContext = vm ?? new FlashCardsViewModel();

            FlashCardsListView.SelectionMode = ListViewSelectionMode.None;
            FlashCardsListView.ItemTapped   += QuestionListView_ItemTapped;


            DataTemplate dataTemplate = new DataTemplate(() => // taken from https://github.com/UniversityOfPlymouthComputing/MobileDev-XamarinForms/blob/master/docs/Chapters/Chapter_4_MasterDetail/listview-delete.md
            {
                //Return a subclass of Cell
                TextCell cell = new TextCell();
                //We can set properties on cell
                MenuItem delete = new MenuItem
                {
                    Text          = "Delete",
                    IsDestructive = true
                };
                MenuItem edit = new MenuItem
                {
                    Text          = "Edit",
                    IsDestructive = true
                };


                delete.SetBinding(MenuItem.CommandProperty, new Binding("DeleteCommand", source: this.BindingContext));

                delete.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));

                edit.SetBinding(MenuItem.CommandProperty, new Binding("EditCommand", source: this.BindingContext));

                edit.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));



                //Add menu item to the cell
                cell.ContextActions.Add(delete);
                cell.ContextActions.Add(edit);

                return(cell);
            });

            dataTemplate.SetBinding(TextCell.TextProperty, "Question");

            //Finally, set the ItemTemplate property (type DataTemplate)
            FlashCardsListView.ItemTemplate = dataTemplate;
        }
コード例 #5
0
        public void ViewModelTestAddACard()
        {
            Group m = new Group();

            m.Setup();
            m.testMode = true;
            FlashCardsViewModel vm = new FlashCardsViewModel("Test", m.Cards, m);

            FlashCard card = new FlashCard("Example question", "Example answer", "Test");

            vm.AddFlashCard(card);
            bool found = false;

            foreach (FlashCard f in vm.AllCards)
            {
                if (f.ToString() == card.ToString())
                {
                    found = true;
                }
            }
            Assert.IsTrue(found); // this should be true
        }