/// <summary> /// Override the excel load to provide functionality. /// </summary> /// <param name="session">The session.</param> protected override void ExecLoad(ISession session) { //base.ExecLoad(session); var allReports = session.Query <Report>() .OrderByDescending(x => x.IsDefaultReport ? x.DateCreated.Value.Date : x.DateCreated.Value) .ThenBy(x => x.Category) .ThenBy(x => x.Name) .ToFuture() .ToObservableCollection(); var allSites = GetAllWebsites(session); AssignWebsiteNames(allReports, allSites); CollectionItems = new ListCollectionView(allReports); if (CollectionItems.Count > 0) { CollectionItems.MoveCurrentToFirst(); } SelectedReport = CollectionItems.CurrentItem as Report; CollectionItems.Filter = CompositeFilter; CollectionItems.MoveCurrentToFirst(); ReportType = ReportTypes[0]; SelectedCategory = Categories[0]; Filters = _filterEnumerationsMainView; FilterText = string.Empty; SelectedFilter = Filters.FirstOrDefault(); }
private void btnFirst_Click(object sender, RoutedEventArgs e) { nodesCollectionView.MoveCurrentToFirst(); if (dgNodes.SelectedItem != null) { //确保选择项可见 dgNodes.ScrollIntoView(dgNodes.SelectedItem); } }
//OnBrowse is called whenever the Next or Previous buttons //are clicked to change the currency private void OnBrowse(object sender, RoutedEventArgs args) { var b = sender as Button; switch (b.Name) { case "Previous": if (MyCollectionView.MoveCurrentToPrevious()) { feedbackText.Text = ""; O = MyCollectionView.CurrentItem as Order; } else { MyCollectionView.MoveCurrentToFirst(); feedbackText.Text = "At first record"; } break; case "Next": if (MyCollectionView.MoveCurrentToNext()) { feedbackText.Text = ""; O = MyCollectionView.CurrentItem as Order; } else { MyCollectionView.MoveCurrentToLast(); feedbackText.Text = "At last record"; } break; } }
//Prevous, Next 버튼 처리 private void OnMove(Button sender) { if (sender == null) { return; } var b = sender as Button; switch (b.Name) { case "Previous": if (MyCollectionView.MoveCurrentToPrevious()) { emp = MyCollectionView.CurrentAddItem as Emp; } else { MyCollectionView.MoveCurrentToFirst(); } break; case "Next": if (MyCollectionView.MoveCurrentToNext()) { emp = MyCollectionView.CurrentAddItem as Emp; } else { MyCollectionView.MoveCurrentToLast(); } break; } }
public void EndOfAlphabetAppearsAtStartOfSortedList() { // Arrange const string projectNameC = "C"; var metadataList = new List <DocumentMetadata> { CreateDocumentMetadata("B"), CreateDocumentMetadata(projectNameC), CreateDocumentMetadata("A") }; var sortOption = new ProjectReverseAlphabeticalSort(); var sortDescription = sortOption.GetSortDescription(); var view = new ListCollectionView(metadataList); // Act view.SortDescriptions.Add(sortDescription); // Assert view.MoveCurrentToFirst(); var firstItem = (DocumentMetadata)view.CurrentItem; Assert.That( firstItem.ProjectNames.DisplayName, Is.EqualTo(projectNameC)); }
public MainProductsViewModel() { _database = new DatabaseProductQueries(); _database.GetSupplier(ref _supplierList); _database.GetCategories(ref _categoryList); GetProductsViewModel(ref _listCollection); _viewCollection = new ListCollectionView(_listCollection); DeleteCommand = new RelayCommand(DeleteExecuted, DeleteCanExecute); SaveCommand = new RelayCommand(SaveExecuted, SaveCanExecute); NewCommand = new RelayCommand(NewExecuted); UndoCommand = new RelayCommand(UndoExecuted, UndoCanExecute); SetImageCommand = new RelayCommand(SetImageExecuted); RemoveImageCommand = new RelayCommand(RemoveImageExecuted, RemoveImageCanExecute); AddCategoryCommand = new RelayCommand(AddCategoryExecuted); RemoveCategoryCommand = new RelayCommand(RemoveCategoryExecuted, RemoveCategoryCanExecute); AddSupplierCommand = new RelayCommand(AddSupplierExecuted); RemoveSupplierCommand = new RelayCommand(RemoveSupplierExecuted, RemoveSupplierCanExecute); UpdateSorting(); _viewCollection.MoveCurrentToFirst(); CurrentMainProductViewModel = this; }
public AnalyzerConfigurationViewModel() { _issuesAnalyzer = ServiceLocator.Resolve <IssuesAnalyzerService>(); Analyzers = new ListCollectionView(_issuesAnalyzer.AnalyzerContext.Analyzers); Analyzers.GroupDescriptions.Add(new PropertyGroupDescription("Category")); Analyzers.MoveCurrentToFirst(); }
/// <summary> /// Instantiates a new AdvancedTabViewModel. /// </summary> /// <param name="tree">The (not null) SkillTree instance to operate on.</param> public AdvancedTabViewModel(SkillTree tree) : base(tree) { _attributes = CreatePossibleAttributes().ToList(); AttributesView = new ListCollectionView(_attributes) { Filter = item => !_addedAttributes.Contains(item), CustomSort = Comparer <string> .Create((s1, s2) => { // Sort by group as in AttrGroupOrder first and then by name. var groupCompare = AttrGroupOrder[AttrToGroupConverter.Convert(s1)].CompareTo( AttrGroupOrder[AttrToGroupConverter.Convert(s2)]); return(groupCompare != 0 ? groupCompare : string.CompareOrdinal(s1, s2)); }) }; AttributesView.GroupDescriptions.Add(new PropertyGroupDescription(".", AttrToGroupConverter)); AttributesView.MoveCurrentToFirst(); AttributeConstraints = new ObservableCollection <AttributeConstraint>(); NewAttributeConstraint = new AttributeConstraint(AttributesView.CurrentItem as string); PseudoAttributesView = new ListCollectionView(_pseudoAttributes) { Filter = item => !_addedPseudoAttributes.Contains((PseudoAttribute)item) }; PseudoAttributesView.SortDescriptions.Add(new SortDescription("Group", ListSortDirection.Ascending)); PseudoAttributesView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); PseudoAttributesView.GroupDescriptions.Add(new PropertyGroupDescription("Group")); PseudoAttributeConstraints = new ObservableCollection <PseudoAttributeConstraint>(); ReloadPseudoAttributes(); DisplayName = L10n.Message("Advanced"); }
public void LatestTimeAppearsAtStartOfSortedList() { // Arrange var now = DateTime.UtcNow; var before = now - TimeSpan.FromHours(1); var after = now + TimeSpan.FromHours(1); var metadataList = new List <DocumentMetadata> { CreateDocumentMetadata(now), CreateDocumentMetadata(after), CreateDocumentMetadata(before) }; var sortOption = new ChronologicalSort(); var sortDescription = sortOption.GetSortDescription(); var view = new ListCollectionView(metadataList); // Act view.SortDescriptions.Add(sortDescription); // Assert view.MoveCurrentToFirst(); var firstItem = (DocumentMetadata)view.CurrentItem; Assert.That(firstItem.ActivatedAt, Is.EqualTo(after)); }
private void OnMove(object sender, RoutedEventArgs e) { var b = sender as Button; switch (b.Name) { case "Previous": if (MyCollectionView.MoveCurrentToPrevious()) { emp = MyCollectionView.CurrentAddItem as Emp; } else { MyCollectionView.MoveCurrentToFirst(); } break; case "Next": if (MyCollectionView.MoveCurrentToNext()) { emp = MyCollectionView.CurrentAddItem as Emp; } else { MyCollectionView.MoveCurrentToLast(); } break; } }
public void BeginningOfAlphabetAppearsAtStartOfSortedList() { // Arrange const string displayNameA = "A"; var metadataList = new List <DocumentMetadata> { CreateDocumentMetadata("B"), CreateDocumentMetadata("C"), CreateDocumentMetadata(displayNameA) }; var sortOption = new AlphabeticalSort(); var sortDescription = sortOption.GetSortDescription(); var view = new ListCollectionView(metadataList); // Act view.SortDescriptions.Add(sortDescription); // Assert view.MoveCurrentToFirst(); var firstItem = (DocumentMetadata)view.CurrentItem; Assert.That(firstItem.DisplayName, Is.EqualTo(displayNameA)); }
//protected double PrintablePageWidth; //protected double PrintablePageHeight; public DocumentPaginatorExtention(PrintableListView listview, Thickness margin, Size printPageArea) { printableListView = listview; PageMargin = margin; pageHeight = printPageArea.Height - PageMargin.Top - PageMargin.Bottom; PageSize = printPageArea; headerSize = listview.HeaderSize; footerSize = listview.FooterSize; if (listview.PageHeaderTemplate != null) { pageHeight -= headerSize.Height; } if (listview.PageFooterTemplate != null) { pageHeight -= footerSize.Height; } if (listview.ReportBody == null) { listview.ReportBody = UIUtility.CreateDeepCopy(listview.View); } for (int index = 0; index < (listview.View as GridView).Columns.Count; index++) { var col = (listview.View as GridView).Columns[index]; (listview.ReportBody as GridView).Columns[index].Width = col.ActualWidth; } ListCollectionView originalData = new ListCollectionView((IList)listview.ItemsSource);// (ListCollectionView)listview.ItemsSource; CollectionViewSource source = new CollectionViewSource(); source.Source = originalData.SourceCollection;//(listview.ItemsSource as ListCollectionView) if (printableListView.Group != null && printableListView.Group.GroupDescriptions != null) { foreach (GroupDescription groupDescription in printableListView.Group.GroupDescriptions) { source.GroupDescriptions.Add(groupDescription); } } if (printableListView.Group != null) { printableListView.Group.groupIndex = 0; printableListView.Group.groupPage = 0; } sourceView = source.View as ListCollectionView; createPages(); pageCount = Pages.Count; isPageCountValid = true; documentPaginatorSource = new DocumentPaginatorSource(this); sourceView.MoveCurrentToFirst(); groupIndex = 0; currentGroupPageCount = 0; }
void backButton_Click(object sender, RoutedEventArgs e) { view.MoveCurrentToPrevious(); if (view.IsCurrentBeforeFirst) { view.MoveCurrentToFirst(); } }
/// <summary> /// Instantiates a new AdvancedTabViewModel. /// </summary> /// <param name="tree">The (not null) SkillTree instance to operate on.</param> /// <param name="dialogCoordinator">The <see cref="IDialogCoordinator"/> used to display dialogs.</param> /// <param name="dialogContext">The context used for <paramref name="dialogCoordinator"/>.</param> /// <param name="runCallback">The action that is called when RunCommand is executed.</param> public AdvancedTabViewModel(SkillTree tree, IDialogCoordinator dialogCoordinator, object dialogContext, Action <GeneratorTabViewModel> runCallback) : base(tree, dialogCoordinator, dialogContext, 3, runCallback) { AdditionalPoints = new LeafSetting <int>(nameof(AdditionalPoints), 21, () => TotalPoints = Tree.Level - 1 + AdditionalPoints.Value); TotalPoints = Tree.Level - 1 + AdditionalPoints.Value; TreePlusItemsMode = new LeafSetting <bool>(nameof(TreePlusItemsMode), false); WeaponClass = new LeafSetting <WeaponClass>(nameof(WeaponClass), Model.PseudoAttributes.WeaponClass.Unarmed, () => WeaponClassIsTwoHanded = WeaponClass.Value.IsTwoHanded()); OffHand = new LeafSetting <OffHand>(nameof(OffHand), Model.PseudoAttributes.OffHand.Shield); Tags = new LeafSetting <Tags>(nameof(Tags), Model.PseudoAttributes.Tags.None); tree.PropertyChanged += (sender, args) => { if (args.PropertyName == nameof(SkillTree.Level)) { TotalPoints = Tree.Level - 1 + AdditionalPoints.Value; } }; _attributes = CreatePossibleAttributes().ToList(); AttributesView = new ListCollectionView(_attributes) { Filter = item => !_addedAttributes.Contains(item), CustomSort = Comparer <string> .Create((s1, s2) => { // Sort by group as in AttrGroupOrder first and then by name. var groupCompare = AttrGroupOrder[AttrToGroupConverter.Convert(s1)].CompareTo( AttrGroupOrder[AttrToGroupConverter.Convert(s2)]); return(groupCompare != 0 ? groupCompare : string.CompareOrdinal(s1, s2)); }) }; AttributesView.GroupDescriptions.Add(new PropertyGroupDescription(".", AttrToGroupConverter)); AttributesView.MoveCurrentToFirst(); AttributeConstraints = new ObservableCollection <AttributeConstraint>(); NewAttributeConstraint = new AttributeConstraint(AttributesView.CurrentItem as string); PseudoAttributesView = new ListCollectionView(_pseudoAttributes) { Filter = item => !_addedPseudoAttributes.Contains((PseudoAttribute)item) }; PseudoAttributesView.SortDescriptions.Add(new SortDescription("Group", ListSortDirection.Ascending)); PseudoAttributesView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); PseudoAttributesView.GroupDescriptions.Add(new PropertyGroupDescription("Group")); PseudoAttributeConstraints = new ObservableCollection <PseudoAttributeConstraint>(); ReloadPseudoAttributes(); DisplayName = L10n.Message("Advanced"); SubSettings = new ISetting[] { AdditionalPoints, Iterations, IncludeChecked, ExcludeCrossed, TreePlusItemsMode, WeaponClass, OffHand, Tags, new ConstraintsSetting(this) }; }
public ViewModel(IReadOnlyList <ChangelogEntry> changelog) { _entries = changelog.Select(x => PieceOfInformation.Create($".chlg.{x.Version}", x.Version, x.Date.ToString(CultureInfo.CurrentUICulture), x.Version, null, x.Changes, false, false)).ToArray(); NotesList = new ListCollectionView(_entries) { CustomSort = this }; NotesList.MoveCurrentToFirst(); }
/// <summary> /// Initializes a new instance of the <see cref="AutomationViewModel"/> class. /// </summary> public AutomationViewModel() { var automationTreeService = ServiceLocator.Resolve <AutomationTreeService>(); _selectedTreeItemService = ServiceLocator.Resolve <SelectedTreeItemService>(); Elements = new ListCollectionView(automationTreeService.Elements); Elements.CurrentChanged += CurrentElementChanged; Elements.MoveCurrentToFirst(); }
private void OnClearFilters() { ShowBlocker = false; ShowCritical = false; ShowMajor = false; ShowMinor = false; ShowInformative = false; issueView.MoveCurrentToFirst(); }
/// <summary> /// Constructor. /// </summary> /// <param name="mainViewModel">The primary view model of the program.</param> public ManageVotesWindow(MainViewModel mainViewModel) { InitializeComponent(); MainViewModel = mainViewModel; MainViewModel.PropertyChanged += MainViewModel_PropertyChanged; // Create filtered, sortable views into the collection for display in the window. VoteView1 = new ListCollectionView(MainViewModel.AllVotesCollection); VoteView2 = new ListCollectionView(MainViewModel.AllVotesCollection); if (VoteView1.CanSort) { IComparer voteCompare = new CustomVoteSort(); //IComparer voteCompare = StringComparer.InvariantCultureIgnoreCase; VoteView1.CustomSort = voteCompare; VoteView2.CustomSort = voteCompare; } if (VoteView1.CanFilter) { VoteView1.Filter = (a) => FilterVotes1(a.ToString()); VoteView2.Filter = (a) => FilterVotes2(a.ToString()); } // Initialize starting selected positions VoteView1.MoveCurrentToPosition(-1); VoteView2.MoveCurrentToFirst(); // Create filtered views for display in the window. VoterView1 = new ListCollectionView(MainViewModel.AllVotersCollection); VoterView2 = new ListCollectionView(MainViewModel.AllVotersCollection); VoterView1.Filter = (a) => FilterVoters(VoteView1, a.ToString()); VoterView2.Filter = (a) => FilterVoters(VoteView2, a.ToString()); // Update the voters to match the votes. VoterView1.Refresh(); VoterView2.Refresh(); // Populate the context menu with known tasks. CreateContextMenuCommands(); InitKnownTasks(); UpdateContextMenu(); // Set the data context for binding. DataContext = this; Filter1String = ""; Filter2String = ""; }
public ViewModel(string key) { NotesList = new ListCollectionView(ImportantTips.Entries.Where(x => !x.IsLimited || AppKeyHolder.IsAllRight).Reverse().ToList()); if (key != null) { NotesList.MoveCurrentTo(ImportantTips.Entries.FirstOrDefault(x => x.Id?.Contains(key) == true)); } else { NotesList.MoveCurrentToFirst(); } }
public ViewModel(string key) { NotesList = new ListCollectionView( ImportantTips.Entries.Where(x => !x.IsLimited || InternalUtils.IsAllRight).OrderBy(x => x.DisplayName).ToList()); if (key != null) { NotesList.MoveCurrentTo(ImportantTips.Entries.FirstOrDefault(x => x.Id?.Contains(key) == true)); } else { NotesList.MoveCurrentToFirst(); } }
/// <summary> /// Initializes a new instance of the <see cref="BindingEditorViewModel"/> class. /// </summary> /// <param name="propertyItem">The property item.</param> public BindingEditorViewModel(PropertyItem propertyItem) { _instance = (DependencyObject)propertyItem.Instance; Sources = new ListCollectionView(Enum.GetValues(typeof(BindingSource))); Sources.MoveCurrentToFirst(); Sources.CurrentChanged += (s, e) => OnSourceChanged(); Modes = new ListCollectionView(Enum.GetValues(typeof(BindingMode))); Modes.MoveCurrentToFirst(); Modes.CurrentChanged += (s, e) => UpdateBinding(); UpdateSourceTriggers = new ListCollectionView(Enum.GetValues(typeof(UpdateSourceTrigger))); UpdateSourceTriggers.MoveCurrentToFirst(); UpdateSourceTriggers.CurrentChanged += (s, e) => UpdateBinding(); SourceList = new ListCollectionView(_pathItems); BuildSourceTree(); _dpd = DependencyPropertyDescriptor.FromProperty(propertyItem.Property); _binding = BindingOperations.GetBinding((DependencyObject)propertyItem.Instance, _dpd.DependencyProperty); if (_binding == null) { UpdateBinding(); } else { if (_binding.Source == null) { Sources.MoveCurrentTo(BindingSource.DataContext); } else if (_binding.RelativeSource != null) { if (_binding.RelativeSource.Mode == RelativeSourceMode.PreviousData) { Sources.MoveCurrentTo(BindingSource.PreviousData); } else if (_binding.RelativeSource.Mode == RelativeSourceMode.TemplatedParent) { Sources.MoveCurrentTo(BindingSource.TemplatedParent); } else if (_binding.RelativeSource.Mode == RelativeSourceMode.FindAncestor) { Sources.MoveCurrentTo(BindingSource.FindAncestor); } } UpdateExpression(); } }
private void OnSetSelectedFormat() { _channelMaskCollection.Clear(); try { if (_selectedFormat != null && _selectedFormat.Masks.Any()) { _channelMaskCollection.AddRange(_selectedFormat.Masks); _channelMaskView.MoveCurrentToFirst(); } } catch { } }
/// <summary> /// Initializes a new instance of the <see cref="VisualTreeViewModel"/> class. /// </summary> public VisualTreeViewModel() { _selectedTreeItemService = ServiceLocator.Resolve <SelectedTreeItemService>(); _selectedTreeItemService.SelectedTreeItemChanged += OnSelectedTreeItemChanged; MouseElementServiceSettings = ServiceLocator.Resolve <MouseElementService>().Settings; var visualTreeElementService = ServiceLocator.Resolve <VisualTreeService>(); visualTreeElementService.ElementsChanged += (s, e) => Elements.Refresh(); //FocusInfo = ServiceLocator.Resolve<FocusedElementService>().Info; Elements = new ListCollectionView(visualTreeElementService.Elements); Elements.CurrentChanged += CurrentElementChanged; Elements.MoveCurrentToFirst(); }
private void ChannelMaskView_CurrentChanged(object sender, System.EventArgs e) { _maskCollection.Clear(); if (_channelMaskView.CurrentItem != null) { try { PixelFormatChannelMask current = (PixelFormatChannelMask)_channelMaskView.CurrentItem; if (current.Mask != null && current.Mask.Any()) { _maskCollection.AddRange(current.Mask); _maskView.MoveCurrentToFirst(); } } catch { } } }
public Window1() { Instruments = new ListCollectionView(instruments = new ObservableCollection <string>(new string[] { "" })); Instruments.CurrentChanged += Instruments_CurrentChanged; InitializeComponent(); if (!fw.CoreFX.LogOn("FX1256627001", "8730", true)) { System.Diagnostics.Debug.Fail("Login"); } else { fw.PendingOrderCompleted += fw_PendingOrderCompleted; fw.TradeAdded += fw_TradeAdded; statsScheduler = new HedgeHog.Schedulers.ThreadScheduler(TimeSpan.FromSeconds(10), TimeSpan.FromMinutes(0.1), () => Corridor(), (s, e) => AddLog(e.Exception.Message)); fw.GetOffers().Select(o => o.Pair).ToList().ForEach(i => instruments.Add(i)); Instruments.MoveCurrentToFirst(); //charter = new Corridors(); //charter.Show(); } new HedgeHog.Statistics.StatisticsWindow().Show(); }
private void SaveExecuted(object sender) { List <ProductModel> changedProducts = new List <ProductModel>(); List <ProductModel> deletedProducts = new List <ProductModel>(); List <ProductVM> deletedViewList = new List <ProductVM>(); foreach (ProductVM item in _listCollection) { if (item.IsDeleted) { item.AcceptChanges(); deletedProducts.Add(item.GetModel()); deletedViewList.Add(item); continue; } else if (item.Changed) { item.AcceptChanges(); changedProducts.Add(item.GetModel()); } else { continue; } } if (deletedViewList.Count != 0) { foreach (ProductVM item in deletedViewList) { _listCollection.Remove(item); } } _database.SaveProductList(ref changedProducts, ref deletedProducts); GetProductsViewModel(ref _listCollection); _viewCollection.Refresh(); _viewCollection.MoveCurrentToFirst(); }
public ViewModel() { _entries = new [] { PieceOfInformation.Create("Properties for: Cars", GetHint(CarObjectTester.Instance)), PieceOfInformation.Create("Properties for: Tracks", GetHint(TrackObjectTester.Instance)), PieceOfInformation.Create("Properties for: Showrooms", GetHint(ShowroomObjectTester.Instance)), PieceOfInformation.Create("Properties for: Car Setups", GetHint(CarSetupObjectTester.Instance)), PieceOfInformation.Create("Properties for: Car Skins", GetHint(CarSkinObjectTester.Instance)), PieceOfInformation.Create("Properties for: Track Skins", GetHint(TrackSkinObjectTester.Instance)), PieceOfInformation.Create("Properties for: Weather", GetHint(WeatherObjectTester.Instance)), PieceOfInformation.Create("Properties for: Replays", GetHint(ReplayObjectTester.Instance)), PieceOfInformation.Create("Properties for: Screenshots", GetHint(FileTester.Instance)), PieceOfInformation.Create("Properties for: Lap Times", GetHint(LapTimeTester.Instance)), PieceOfInformation.Create("Properties for: Challenges", GetHint(SpecialEventObjectTester.Instance)), PieceOfInformation.Create("Properties for: Online", GetHint(ServerEntryTester.Instance)), }; NotesList = new ListCollectionView(Filtering.Entries.Concat(_entries).ToList()) { CustomSort = this }; NotesList.MoveCurrentToFirst(); }
public DroppedFilesViewModel(string mediaType, string file, IDialogCoordinator dialogService, CustomDialog customDialog) { MediaType = mediaType; _customDialog = customDialog; CloseAllPendingFileDropCommand = new DelegateCommand(async() => { await CloseDialog(dialogService, _customDialog); }); CloseDialogCommand = new DelegateCommand(async() => { cancelPending = true; await dialogService.HideMetroDialogAsync(this, _customDialog); cancelPending = false; }); SaveNewFileCommand = new DelegateCommand(async() => { try { ProcessFile(DroppedFileName, SelectedFolder, FileNameToSave); } catch (Exception) { } await dialogService.HideMetroDialogAsync(this, _customDialog); }); CardPositionsArray = new ListCollectionView(Enum.GetNames(typeof(CardPosition))); CardPositionsArray.MoveCurrentToFirst(); CardPositionsArray.CurrentChanged += CardPositionsArray_CurrentChanged; Load(file); }
public bool MoveCurrentToFirst() { return(view.MoveCurrentToFirst()); }
/// <summary> /// 選択中のモジュールを削除 /// </summary> /// <param name="dataGrid"></param> private void DeleteModules(DataGrid dataGrid) { var currPos = _CollectionView.CurrentPosition; // モジュール数を編集した後に削除するとcurrPosが-1になる場合があるため、 // ここで最初に選択されている表示上のモジュールの要素番号を取得する if (currPos == -1) { var cnt = 0; foreach (var module in _CollectionView.OfType <ModulesGridItem>()) { if (module.IsSelected) { currPos = cnt; break; } cnt++; } } var items = CollectionViewSource.GetDefaultView(_CollectionView) .Cast <ModulesGridItem>() .Where(x => x.IsSelected); _ModulesInfo.Modules.RemoveRange(items); // 削除後に全部の選択状態を外さないと余計なものまで選択される foreach (var module in _ModulesInfo.Modules) { module.IsSelected = false; } // 選択行を設定 if (currPos < 0) { // 先頭行を削除した場合 _CollectionView.MoveCurrentToFirst(); } else if (_CollectionView.Count <= currPos) { // 最後の行を消した場合、選択行を最後にする _CollectionView.MoveCurrentToLast(); } else { // 中間行の場合 _CollectionView.MoveCurrentToPosition(currPos); } // 再度選択 if (_CollectionView.CurrentItem is ModulesGridItem item) { item.IsSelected = true; } // セルフォーカス if (dataGrid.CurrentCell.Column is not null) { CellFocusCommand?.Execute(new Tuple <DataGrid, int, int>(dataGrid, _CollectionView.CurrentPosition, dataGrid.CurrentCell.Column.DisplayIndex)); } }