Example #1
0
        private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            var vm = (SegmentsViewModel)sender;

            switch (e.PropertyName)
            {
            case "Varieties":
                DispatcherHelper.CheckBeginInvokeOnUI(LoadCollectionView);
                break;

            case "SelectedSegment":
                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    if (_selectMonitor.Busy)
                    {
                        return;
                    }

                    using (_selectMonitor.Enter())
                    {
                        SegmentsDataGrid.SelectedCellRanges.Clear();
                        if (vm.SelectedSegment != null)
                        {
                            VarietyViewModel variety = vm.SelectedSegment.Variety;
                            int itemIndex            = SegmentsDataGrid.Items.IndexOf(variety);
                            SegmentsDataGrid.BringItemIntoView(variety);
                            SegmentsDataGrid.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                var row = (DataRow)SegmentsDataGrid.GetContainerFromIndex(itemIndex);
                                if (row != null)
                                {
                                    Cell cell = row.Cells.Single(c => c.DataContext == vm.SelectedSegment);
                                    SegmentsDataGrid.SelectedCellRanges.Add(new SelectionCellRange(itemIndex, cell.ParentColumn.Index));
                                    cell.BringIntoView();
                                }
                            }), DispatcherPriority.Background);
                        }
                    }
                });
                break;
            }
        }
        private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            var vm = (SegmentMappingsTableViewModel)sender;

            switch (e.PropertyName)
            {
            case "SelectedSegmentPair":
                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    if (_selectMonitor.Busy)
                    {
                        return;
                    }

                    using (_selectMonitor.Enter())
                    {
                        SegmentsDataGrid.SelectedCellRanges.Clear();
                        if (vm.SelectedSegmentPair != null)
                        {
                            SegmentMappingsTableSegmentViewModel segment = vm.SelectedSegmentPair.Segment1;
                            int itemIndex = SegmentsDataGrid.Items.IndexOf(segment);
                            SegmentsDataGrid.BringItemIntoView(segment);
                            SegmentsDataGrid.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                var row = (DataRow)SegmentsDataGrid.GetContainerFromIndex(itemIndex);
                                if (row != null)
                                {
                                    Cell cell = row.Cells.Single(c => c.Content == vm.SelectedSegmentPair);
                                    SegmentsDataGrid.SelectedCellRanges.Add(new SelectionCellRange(itemIndex, cell.ParentColumn.Index));
                                    SegmentsDataGrid.CurrentItem   = segment;
                                    SegmentsDataGrid.CurrentColumn = cell.ParentColumn;
                                    cell.BringIntoView();
                                }
                            }), DispatcherPriority.Background);
                        }
                    }
                });
                break;
            }
        }