using System.Windows;
using MVVMProject.ViewModels;
using MVVMProject.Views.TasksViews;

namespace MVVMProject.Views
{
    public partial class Tasks
    {
        public Tasks()
        {
            InitializeComponent();

            // Set the DataContext to an instance of the view model class
            var viewModel = new TasksViewModel();
            DataContext = viewModel;

            // Child user controls (inherit DataContext from this user control)
            List = new List(); // RadGridView
            Details = new Details(); // Form

            // Show the RadGridView first
            ContentControl1.Content = List;

            // Listeners for the view model's events
            viewModel.ItemSelected += OnItemSelected;
            viewModel.SaveCompleted += OnSaveCompleted;
        }

        void OnItemSelected(object sender, RoutedEventArgs e)
        {
            // Show the form
            ContentControl1.Content = Details;
        }

        void OnSaveCompleted(object sender, RoutedEventArgs e)
        {
            // Show the RadGridView
            ContentControl1.Content = List;
        }

        public List List { get; set; }

        public Details Details { get; set; }
    }
}