// TODO: 06 - The EmployeeSummaryView contains a Tab control which defines a region named TabRegion (EmployeeSummaryView.xaml).
        // TODO: 07 - The TabRegion defines a RegionContext which provides a reference to the currently selected employee to all child views (EmployeeSummaryView.xaml).
        public EmployeeSummaryView(EmployeeSummaryViewModel viewModel)
        {
            this.InitializeComponent();

            // Set the ViewModel as this View's data context.
            this.DataContext = viewModel;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called when a new employee is selected. This method uses
        /// view injection to programmatically
        /// </summary>
        private void EmployeeSelected(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return;
            }

            // Get the employee entity with the selected ID.
            Employee selectedEmployee = this.dataService.GetEmployees().FirstOrDefault(item => item.Id == id);

            // TODO: 05 - The MainRegionController displays the EmployeeSummaryView in the Main region when an employee is first selected.

            // Get a reference to the main region.
            IRegion mainRegion = this.regionManager.Regions[RegionNames.MainRegion];

            if (mainRegion == null)
            {
                return;
            }

            // Check to see if we need to create an instance of the view.
            EmployeeSummaryView view = mainRegion.GetView("EmployeeSummaryView") as EmployeeSummaryView;

            if (view == null)
            {
                // Create a new instance of the EmployeeDetailsView using the Unity container.
                view = this.container.Resolve <EmployeeSummaryView>();

                // Add the view to the main region. This automatically activates the view too.
                mainRegion.Add(view, "EmployeeSummaryView");
            }
            else
            {
                // The view has already been added to the region so just activate it.
                mainRegion.Activate(view);
            }

            // Set the current employee property on the view model.
            EmployeeSummaryViewModel viewModel = view.DataContext as EmployeeSummaryViewModel;

            if (viewModel != null)
            {
                viewModel.CurrentEmployee = selectedEmployee;
            }
        }
        public EmployeeSummaryView(EmployeeSummaryViewModel viewModel)
        {
            InitializeComponent();

            DataContext = viewModel;
        }