private static void PopulateTabControl(TabablzControl tabablzControl, LayoutStructureTabSet layoutStructureTabSet)
        {
            bool wasAnyTabSelected = false;

            foreach (var tabItem in layoutStructureTabSet.TabItems)
            {
                var view = ViewLocator.LocateForModelType(tabItem.ViewModelType, null, null);
                var vm   = typeof(IoC).GetMethod("Get").MakeGenericMethod(tabItem.ViewModelType).Invoke(tabablzControl, new Object[] { null });

                ViewModelBinder.Bind(vm, view, null);
                (tabablzControl.DataContext as ShellViewModel).ActivateItem(vm as IScreen);

                tabablzControl.AddToSource(view);

                if (tabItem.Id == layoutStructureTabSet.SelectedTabItemId)
                {
                    tabablzControl.Dispatcher.BeginInvoke(new System.Action(() =>
                    {
                        tabablzControl.SetCurrentValue(Selector.SelectedItemProperty, view);
                    }), DispatcherPriority.Loaded);
                    wasAnyTabSelected = true;
                }
            }

            if (!wasAnyTabSelected && tabablzControl.Items.Count != 0)
            {
                tabablzControl.Dispatcher.BeginInvoke(new System.Action(() =>
                {
                    tabablzControl.SetCurrentValue(Selector.SelectedItemProperty, tabablzControl.Items.OfType <System.Windows.Controls.UserControl>().First());
                }), DispatcherPriority.Loaded);
                wasAnyTabSelected = true;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Restores the state of the tabSet
        /// </summary>
        /// <typeparam name="TTabModel">The type of tab model</typeparam>
        /// <typeparam name="TTabViewModel">The type of tab view model to be displayed in the app.</typeparam>
        /// <param name="tabablzControl">The control in which to restore the items</param>
        /// <param name="tabSetState">The state of the tab set to be restored</param>
        /// <param name="viewModelFactory">The function that creates the view model based on a model</param>
        public static void RestoreTabSetState <TTabModel, TTabViewModel>(TabablzControl tabablzControl, TabSetState <TTabModel> tabSetState, Func <TTabModel, TTabViewModel> viewModelFactory)
        {
            foreach (var tabModel in tabSetState.TabItems)
            {
                tabablzControl.AddToSource(viewModelFactory(tabModel));
            }

            tabablzControl.Dispatcher.BeginInvoke(new Action(() =>
            {
                tabablzControl.SelectedIndex = tabSetState.SelectedTabItemIndex ?? -1;
            }), DispatcherPriority.Loaded);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Restores the state of the tab set.
        /// </summary>
        /// <typeparam name="TTabModel">The type of tab model</typeparam>
        /// <typeparam name="TTabViewModel">The type of tab view model to be displayed in the app.</typeparam>
        /// <param name="tabablzControl">The control in which to restore the items</param>
        /// <param name="tabSetState">The state of the tab set to be restored</param>
        /// <param name="viewModelFactory">The function that creates the view model based on a model</param>
        public static void RestoreTabSetState <TTabModel, TTabViewModel> (TabablzControl tabablzControl, TabSetState <TTabModel> tabSetState, Func <TTabModel, TTabViewModel> viewModelFactory)
        {
            var restoreSelectedTabItem = (Action)(() => tabablzControl.SelectedIndex = tabSetState.SelectedTabItemIndex ?? -1);

            foreach (var tabModel in tabSetState.TabItems)
            {
                var tabViewModel = viewModelFactory(tabModel);
                if (tabViewModel != null)
                {
                    tabablzControl.AddToSource(tabViewModel);
                }
            }

            tabablzControl.Dispatcher.BeginInvoke(restoreSelectedTabItem, DispatcherPriority.Loaded);
        }
Ejemplo n.º 4
0
        private void PopulateTabControl(TabablzControl tabablzControl, LayoutStructureTabSet layoutStructureTabSet)
        {
            foreach (var tabItem in layoutStructureTabSet.TabItems)
            {
                var featureFactory         = _featureRegistry[tabItem.FeatureId];
                var tabContentLifetimeHost = featureFactory.RestoreTabContent(tabItem);
                var tabContentContainer    = new TabItemContainer(tabItem.Id, featureFactory.FeatureId, tabContentLifetimeHost, featureFactory);
                tabablzControl.AddToSource(tabContentContainer);

                if (tabContentContainer.TabId == layoutStructureTabSet.SelectedTabItemId)
                {
                    tabablzControl.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        tabablzControl.SetCurrentValue(Selector.SelectedItemProperty, tabContentContainer);
                    }), DispatcherPriority.Loaded);
                }
            }
        }