private void OnGameEntities_ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var listBox           = sender as ListBox;
            var newSelection      = listBox.SelectedItems.Cast <GameEntity>().ToList();
            var previousSelection = newSelection.Except(e.AddedItems.Cast <GameEntity>()).Concat(e.RemovedItems.Cast <GameEntity>()).ToList();

            Project.UndoRedo.Add(new UndoRedoAction(
                                     () => // undo action
            {
                listBox.UnselectAll();
                previousSelection.ForEach(x => (listBox.ItemContainerGenerator.ContainerFromItem(x) as ListBoxItem).IsSelected = true);
            },
                                     () => //redo action
            {
                listBox.UnselectAll();
                newSelection.ForEach(x => (listBox.ItemContainerGenerator.ContainerFromItem(x) as ListBoxItem).IsSelected = true);
            },
                                     "Selection changed"
                                     ));

            MSGameEntity msEntity = null;

            if (newSelection.Any())
            {
                msEntity = new MSGameEntity(newSelection);
            }
            GameEntityView.Instance.DataContext = msEntity;
        }
Exemple #2
0
        private void OnGameEntitys_ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //GameEntityView.Instance.DataContext = null;
            var listBox = sender as ListBox;
            //if (e.AddedItems.Count > 0)
            //{
            //    GameEntityView.Instance.DataContext = listBox.SelectedItems[0];
            //}
            var newSelection      = listBox.SelectedItems.Cast <GameEntity>().ToList();
            var previousSelection = newSelection.Except(e.AddedItems.Cast <GameEntity>())
                                    .Concat(e.RemovedItems.Cast <GameEntity>()).ToList();
            //Project.UndoRedo.Add(new UndoRedoAction(
            //    () =>//Undo Action
            //    {
            //        listBox.UnselectAll();
            //        previousSelection.ForEach(x => (listBox.ItemContainerGenerator.ContainerFromItem(x) as ListBoxItem).IsSelected = true);
            //    },
            //    () =>//Redo Action
            //    {
            //        listBox.UnselectAll();
            //        newSelection.ForEach(x => (listBox.ItemContainerGenerator.ContainerFromItem(x) as ListBoxItem).IsSelected = true);
            //    },
            //    "Selection Changed"));
            MSGameEntity msEntity = null;

            if (newSelection.Any())
            {
                msEntity = new MSGameEntity(newSelection);
            }
            GameEntityView.Instance.DataContext = msEntity;
        }