示例#1
0
        /// <summary>
        /// 'Expander' is part of the toggle button defined in the XAML that shows the [+] or [-]
        /// sign when there are items under the current watch variable that can be inspected.
        /// To maximise efficiency, the expansion of items must happen only when the expander is clicked
        /// when showing [+]. This generated the child items from the Virtual Machine.
        /// </summary>
        /// <param name="sender"> The sender is the Toggle Button</param>
        /// <param name="e"></param>
        private void OnExpanderClicked(object sender, RoutedEventArgs e)
        {
            if (null == inspectionData) // Not possible...
            {
                return;                 // ... but, just to be sure.
            }
            Logger.LogInfo("Insepction-OnExpanderClicked", "OnExpanderClicked");
            ToggleButton expanderToggle = (ToggleButton)sender;

            // The parent we are trying to locate here is the InspectionViewItem. The
            // expander is buried beneath several layers of stackpanels and grids under the Item
            // and therefore we have to make numerous calls to find the InspectionViewItem.
            InspectionViewItem parent = (InspectionViewItem)VisualTreeHelper.GetParent
                                            (VisualTreeHelper.GetParent
                                                (VisualTreeHelper.GetParent
                                                    (VisualTreeHelper.GetParent
                                                        (VisualTreeHelper.GetParent
                                                            (VisualTreeHelper.GetParent(expanderToggle))))));

            // expanderToggle.IsChecked == true means the [+] --> [-]
            if (expanderToggle.IsChecked == true)
            {
                parent.IsExpanded = false;
                InspectionData selectedData = (InspectionData)parent.DataContext;
                inspectionData.ExpandInspection(selectedData);

                // If there is a large amount of data, the user may have to wait.
                // This is indicated by updating the mouse cursor.
                Mouse.SetCursor(Cursors.Wait);
                parent.IsSelected       = true;
                parent.IsExpanded       = true;
                selectedData.IsExpanded = true;

                CheckExpansion(inspectionData.Data);
                inspectionToolTip.Items.Refresh();
                DoExpansion(inspectionData.Data);
                Mouse.SetCursor(Cursors.Arrow);

                // In the tooltip, the width of items may vary and the user cannot adjust the width
                // of the datagrid. Therefore there must be a way top retrieve the maximum width of each column
                // and adjust the setting so that the Inspection Values are not blocked for the user
                colName.Width  = inspectionData.MaxNameWidth();
                colValue.Width = inspectionData.MaxValueWidth();
                this.Width     = colName.Width + colValue.Width;
            }
        }
        /// <summary>
        /// 'Expander' is part of the toggle button defined in the XAML that shows the [+] or [-]
        /// sign when there are items under the current watch variable that can be inspected.
        /// To maximise efficiency, the expansion of items must happen only when the expander is clicked
        /// when showing [+]. This generated the child items from the Virtual Machine.
        /// </summary>
        /// <param name="sender"> The sender is the Toggle Button</param>
        /// <param name="e"></param>
        private void OnExpanderClicked(object sender, RoutedEventArgs e)
        {
            ToggleButton expanderToggle = (ToggleButton)sender;

            if (null == expanderToggle)
            {
                return;
            }

            // The parent we are trying to locate here is the InspectionViewItem. The
            // expander is buried beneath several layers of stackpanels and grids under the Item
            // and therefore we have to make numerous calls to find the InspectionViewItem.
            InspectionViewItem parent = (InspectionViewItem)VisualTreeHelper.GetParent
                                            (VisualTreeHelper.GetParent
                                                (VisualTreeHelper.GetParent
                                                    (VisualTreeHelper.GetParent
                                                        (VisualTreeHelper.GetParent
                                                            (VisualTreeHelper.GetParent(expanderToggle))))));

            object         data         = ((null == parent) ? null : parent.DataContext);
            InspectionData selectedData = data as InspectionData;

            if (null == selectedData)
            {
                return;
            }

            // expanderToggle.IsChecked == true means the [+] --> [-]
            if (expanderToggle.IsChecked == true)
            {
                parent.IsExpanded = false;
                dataCollection.ExpandInspection(selectedData);
                parent.IsExpanded = true;

                UpdateExpansionStates();
                inspectionView.Items.Refresh();
                DoExpansion(dataCollection.Data);

#if false
                parent.IsExpanded = false;
                InspectionData selectedData = (InspectionData)parent.DataContext;
                dataCollection.ExpandInspection(selectedData);

                // If there is a large amount of data, the user may have to wait.
                // This is indicated by updating the mouse cursor.
                Mouse.SetCursor(Cursors.Wait);
                parent.IsSelected       = true;
                parent.IsExpanded       = true;
                selectedData.IsExpanded = true;

                UpdateExpansionStates();
                inspectionView.Items.Refresh();
                DoExpansion(dataCollection.Data);
                Mouse.SetCursor(Cursors.Arrow);
#endif
            }

            // Select the item that is currently being expanded/collapsed.
            InspectionViewItem itemToSelect = ContainerFromItem(selectedData);
            if (null != itemToSelect)
            {
                itemToSelect.IsSelected = true;
            }
        }