Example #1
0
        private ListSelectionState GetSelectionState()
        {
            var listSelectionState = new ListSelectionState();

            foreach (ItemDataSource selectedItem in ListView.SelectedItems)
            {
                listSelectionState.SelectedItemDataSources.Add(selectedItem);
            }
            var caretItem = _data.CaretItem;

            if (caretItem != null)
            {
                listSelectionState.CaretItemDataSource = caretItem;
            }
            return(listSelectionState);
        }
Example #2
0
        private void RestoreSelectionState(ListSelectionState state)
        {
            ListView.SelectedItems.Clear();
            ItemDataSource tempItem = null;

            foreach (ItemDataSource item in ListView.Items)
            {
                var index = state.SelectedItemDataSources.IndexOf(item);
                if (index >= 0)
                {
                    state.SelectedItemDataSources.RemoveAt(index);
                    ListView.SelectedItems.Add(item);
                }

                if (item == state.CaretItemDataSource)
                {
                    tempItem = item;
                }
            }

            _data.CaretItem = tempItem;
        }