Example #1
0
 public DialogsViewModel()
 {
     //Sample 4
     OpenSample4DialogCommand   = new AnotherCommandImplementation(OpenSample4Dialog);
     AcceptSample4DialogCommand = new AnotherCommandImplementation(AcceptSample4Dialog);
     CancelSample4DialogCommand = new AnotherCommandImplementation(CancelSample4Dialog);
 }
        public TreesViewModel()
        {
            MovieCategories = new ObservableCollection <MovieCategory>
            {
                new MovieCategory("Action",
                                  new Movie("Predator", "John McTiernan"),
                                  new Movie("Alien", "Ridley Scott"),
                                  new Movie("Prometheus", "Ridley Scott")),
                new MovieCategory("Comedy",
                                  new Movie("EuroTrip", "Jeff Schaffer"),
                                  new Movie("EuroTrip", "Jeff Schaffer")
                                  )
            };

            AddCommand = new AnotherCommandImplementation(
                _ =>
            {
                if (!MovieCategories.Any())
                {
                    MovieCategories.Add(new MovieCategory(GenerateString(15)));
                }
                else
                {
                    var index = new Random().Next(0, MovieCategories.Count);

                    MovieCategories[index].Movies.Add(
                        new Movie(GenerateString(15), GenerateString(20)));
                }
            });

            RemoveSelectedItemCommand = new AnotherCommandImplementation(
                _ =>
            {
                var movieCategory = SelectedItem as MovieCategory;
                if (movieCategory != null)
                {
                    MovieCategories.Remove(movieCategory);
                }
                else
                {
                    var movie = SelectedItem as Movie;
                    if (movie == null)
                    {
                        return;
                    }
                    MovieCategories.FirstOrDefault(v => v.Movies.Contains(movie))?.Movies.Remove(movie);
                }
            },
                _ => SelectedItem != null);
        }