Beispiel #1
0
        /// <summary>
        /// This delagate is called when the view model is changed.
        /// </summary>
        /// <param name="pObject">The event sender.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        private static void OnViewModelChanged(DependencyObject pObject, DependencyPropertyChangedEventArgs pEventArgs)
        {
            TreeListView lTreeListView = pObject as TreeListView;

            if (lTreeListView != null && lTreeListView.InnerListView != null)
            {
                // Unloading the view model from the inner list.
                lTreeListView.InnerListView.ViewModel = null;

                // Invalidating the old view model.
                IRootHierarchicalItemViewModel lOldViewModel = pEventArgs.OldValue as IRootHierarchicalItemViewModel;
                if (lOldViewModel != null)
                {
                    lOldViewModel.PropertyChanged       -= lTreeListView.OnRootViewModelPropertyChanged;
                    lOldViewModel.ItemViewModelModified -= lTreeListView.OnItemViewModelModified;
                }

                // Loading the new view model.
                lTreeListView.LoadViewModel();

                // Notifying the user.
                if (lTreeListView.ViewModelChanged != null)
                {
                    lTreeListView.ViewModelChanged(lTreeListView, pEventArgs);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// This delagate is called when the view model is changed.
        /// </summary>
        /// <param name="pSender">The event sender.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        private static void OnViewModelChanged(DependencyObject pSender, DependencyPropertyChangedEventArgs pEventArgs)
        {
            ExtendedListView lExtendedListView = pSender as ExtendedListView;

            if (lExtendedListView != null)
            {
                // Unloading the old view model.
                IRootHierarchicalItemViewModel lOldViewModel = pEventArgs.OldValue as IRootHierarchicalItemViewModel;
                if (lOldViewModel != null)
                {
                    // Unregistering from items modification events.
                    lOldViewModel.ItemViewModelsAdded   -= lExtendedListView.OnItemViewModelsAdded;
                    lOldViewModel.ItemViewModelsRemoved -= lExtendedListView.OnItemViewModelsRemoved;
                    lOldViewModel.ItemViewModelMoved    -= lExtendedListView.OnItemViewModelMoved;

                    // Initializing the view model.
                    lExtendedListView.DropChildrenItems(lOldViewModel, false);
                }

                // Loading the new view model.
                IRootHierarchicalItemViewModel lNewViewModel = pEventArgs.NewValue as IRootHierarchicalItemViewModel;
                if (lNewViewModel != null)
                {
                    // Registering on items modification events.
                    lNewViewModel.ItemViewModelsAdded   += lExtendedListView.OnItemViewModelsAdded;
                    lNewViewModel.ItemViewModelsRemoved += lExtendedListView.OnItemViewModelsRemoved;
                    lNewViewModel.ItemViewModelMoved    += lExtendedListView.OnItemViewModelMoved;

                    // Loading the first level items.
                    lExtendedListView.LoadsChildrenItems(lNewViewModel);
                }
            }
        }