Example #1
0
        /// <summary>
        /// Updates the selected <see cref="DataGridColumnHeader"/>.
        /// </summary>
        /// <param name="datagrid">The datagrid.</param>
        private static void UpdateSelectedHeaders(DataGridControl datagrid)
        {
            if (null == datagrid)
            {
                return;
            }

            // Get the list of headers
            IList <DependencyObject> headers = VisualTreeHelperExtended.GetAllDescendants(datagrid, typeof(DataGridColumnHeader));

            if (null == headers || 0 == headers.Count)
            {
                return;
            }

            // Update the selection based on the current tracking modes
            SelectionTrackingModes trackingModes = GetTrackingModes(datagrid);

            if (0 != (trackingModes & SelectionTrackingModes.Headers))
            {
                // Update header selections, if any
                foreach (DataGridColumnHeader header in headers)
                {
                    // Determine if the column associated with this header has any selected cells
                    bool isSelected = false;
                    foreach (DataGridCellInfo cellInfo in datagrid.SelectedCells)
                    {
                        if (cellInfo.Column == header.Column)
                        {
                            isSelected = true;
                            break;
                        }
                    }

                    // Update the selection for this header
                    if (isSelected != GetIsSelectedHeader(header))
                    {
                        if (isSelected)
                        {
                            header.SetValue(IsSelectedHeaderPropertyKey, true);
                        }
                        else
                        {
                            header.ClearValue(IsSelectedHeaderPropertyKey);
                        }
                    }
                }
            }
            else
            {
                // Clear header selections, if any
                foreach (DataGridColumnHeader header in headers)
                {
                    if (GetIsSelectedHeader(header))
                    {
                        header.ClearValue(IsSelectedHeaderPropertyKey);
                    }
                }
            }
        }
Example #2
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // NON-PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Focuses the specified content element.
        /// </summary>
        /// <param name="contentElement">The <see cref="FrameworkElement"/> to focus.</param>
        private void FocusContentElement(FrameworkElement contentElement)
        {
            var firstFocusableElement = VisualTreeHelperExtended.GetFirstFocusableDescendant(contentElement) as FrameworkElement;

            if (firstFocusableElement != null)
            {
                // If a DockSite is the first focusable element, try to activate a docking window
                var dockSite = firstFocusableElement as DockSite;
                if (dockSite != null)
                {
                    if (dockSite.Documents.Count > 0)
                    {
                        dockSite.ActivatePrimaryDocument();
                        return;
                    }
                    if (dockSite.ToolWindows.Count > 0)
                    {
                        dockSite.ToolWindows[0].Activate();
                        return;
                    }
                }
            }

            // Move focus to the first focusable element (if it is still in the presenter)
            contentElement.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
        }
Example #3
0
        /// <summary>
        /// Occurs when the <c>Layout.EvenlyDistributeFavorFocused</c> menu item is clicked.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param>
        private void OnLayoutEvenlyDistributeFavorFocusedMenuItemClick(object sender, RoutedEventArgs e)
        {
            var descendents = VisualTreeHelperExtended.GetAllDescendants <SplitContainer>(dockSite);

            if (descendents != null)
            {
                foreach (var splitContainer in descendents)
                {
                    // Look for SplitContainers that contain the focused element, and increase the ratios for that slot
                    var visualCount   = splitContainer.Children.Count;
                    var desiredRatios = new double[visualCount];
                    for (int i = 0, visibleChildCount = 0; i < visualCount; i++)
                    {
                        // Default ratio, must also ensure that we don't pass a ratio that is less than or equal to 0
                        desiredRatios[i] = 1;

                        // Get the child and verify that it is visible
                        var child = splitContainer.Children[i] as FrameworkElement;
                        if ((child != null) && (child.Visibility == Visibility.Visible))
                        {
                            // If the child has the keyboard focus, then increase it's ratio
                            if (child.IsKeyboardFocusWithin)
                            {
                                desiredRatios[visibleChildCount] = 3;
                            }
                            visibleChildCount++;
                        }
                    }

                    splitContainer.ResizeSlots(desiredRatios);
                }
            }
        }
Example #4
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // NON-PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Handles the <c>Click</c> event of the toggle clock state button.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void OnToggleClockStateButtonClick(object sender, RoutedEventArgs e)
        {
            ListBoxItem item = VisualTreeHelperExtended.GetCurrentOrAncestor(sender as DependencyObject, typeof(ListBoxItem)) as ListBoxItem;

            if (null != item)
            {
                Employee employee = item.DataContext as Employee;
                if (null != employee)
                {
                    if (employee.ClockState == ClockInOutState.Out)
                    {
                        if (this.InactiveEmployees.Remove(employee))
                        {
                            this.ActiveEmployees.Add(employee);
                            employee.ClockState             = ClockInOutState.In;
                            this.activeListBox.SelectedItem = employee;
                        }
                    }
                    else
                    {
                        if (this.ActiveEmployees.Remove(employee))
                        {
                            this.InactiveEmployees.Add(employee);
                            employee.ClockState = ClockInOutState.Out;
                            this.inactiveListBox.SelectedItem = employee;
                        }
                    }
                }
            }
        }
Example #5
0
        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            // If the IsVisible property changes...
            if (e.Property == IsVisibleProperty)
            {
                if (!(bool)e.NewValue)
                {
                    // The menu is hiding so clear the current selection
                    CurrentSelection = null;
                }

                // If the Menu is in a ContextMenu, ensure focus moves out of the context menu and into this Menu
                // after it is displayed... otherwise arrow keys won't work
                Dispatcher.BeginInvoke(
                    DispatcherPriority.Send,
                    (Action)
                    (() =>
                {
                    var contextMenuParent = Keyboard.FocusedElement as ContextMenu;
                    if (contextMenuParent != null &&
                        VisualTreeHelperExtended.GetAncestor(this, typeof(ContextMenu)) == contextMenuParent)
                    {
                        Focus();
                    }
                }));
            }

            base.OnPropertyChanged(e);
        }
        /// <summary>
        /// Updates the focused <see cref="DataGridColumnHeader"/>.
        /// </summary>
        private static void UpdateFocusedHeader(DataGridControl datagrid)
        {
            if (null == datagrid)
            {
                return;
            }

            // Get the list of headers
            IList <DependencyObject> headers = VisualTreeHelperExtended.GetAllDescendants(datagrid, typeof(DataGridColumnHeader));

            if (null == headers || 0 == headers.Count)
            {
                return;
            }

            // Update the focus based on the current tracking Modes
            FocusTrackingModes trackingModes = GetTrackingModes(datagrid);

            if (0 != (trackingModes & FocusTrackingModes.Headers))
            {
                // Get the focused cell, if any, and look for an ancestor cell when editing cell
                DataGridCell cell = Keyboard.FocusedElement as DataGridCell;
                if (cell == null)
                {
                    cell = VisualTreeHelperExtended.GetAncestor(Keyboard.FocusedElement as FrameworkElement, typeof(DataGridCell)) as DataGridCell;
                }

                // Update header focus, if any
                foreach (DataGridColumnHeader header in headers)
                {
                    // Determine if the column associated with this header if focused
                    bool isFocused = (null != cell && cell.Column == header.Column);

                    // Update the focus for this header
                    if (isFocused != GetIsFocusedHeader(header))
                    {
                        if (isFocused)
                        {
                            header.SetValue(IsFocusedHeaderPropertyKey, true);
                        }
                        else
                        {
                            header.ClearValue(IsFocusedHeaderPropertyKey);
                        }
                    }
                }
            }
            else
            {
                // Clear header focus, if any
                foreach (DataGridColumnHeader header in headers)
                {
                    if (GetIsFocusedHeader(header))
                    {
                        header.ClearValue(IsFocusedHeaderPropertyKey);
                    }
                }
            }
        }
Example #7
0
        public static DockSite FindDock()
        { //  Modified to use Actipro's helper methods, since I need to be bound to Actipro for
          //  the DockSite I might as well use their helper methods :)
          //  TODO: Fix This
            var rootVisual = VisualTreeHelperExtended.GetRoot(Application.Current.MainWindow);

            return(VisualTreeHelperExtended.GetAllDescendants(rootVisual, typeof(DockSite)).FirstOrDefault() as DockSite);
        }
Example #8
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // NON-PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Handles the <c>Click</c> event of the close button.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void OnCloseButtonClick(object sender, RoutedEventArgs e)
        {
            ZoomContentControl zoomContentControl = VisualTreeHelperExtended.GetAncestor(this, typeof(ZoomContentControl)) as ZoomContentControl;

            if (null != zoomContentControl)
            {
                zoomContentControl.Overlays.Remove(this);
            }
        }
Example #9
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // NON-PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Occurs when the <c>Layout.EvenlyDistribute</c> menu item is clicked.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param>
        private void OnLayoutEvenlyDistributeMenuItemClick(object sender, RoutedEventArgs e)
        {
            var descendents = VisualTreeHelperExtended.GetAllDescendants <SplitContainer>(dockSite);

            if (descendents != null)
            {
                foreach (var splitContainer in descendents)
                {
                    splitContainer.ResizeSlots();
                }
            }
        }
        /// <summary>
        /// Occurs when the list is double-clicked.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">A <see cref="MouseButtonEventArgs"/> that contains the event data.</param>
        private void OnQatItemsListBoxMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DependencyObject mouseOver = e.OriginalSource as DependencyObject;

            if (mouseOver != null)
            {
                ListBoxItem item = (ListBoxItem)VisualTreeHelperExtended.GetCurrentOrAncestor(mouseOver, typeof(ListBoxItem));
                if ((item != null) && (removeFromQatButton.IsEnabled))
                {
                    removeFromQatButton.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                }
            }
        }
Example #11
0
        public void Show(object rootModel)
        {
            var dockingWindow = CreateDockingWindow(rootModel, _dockSite);

            //dockingWindow.Open();
            dockingWindow.Activate();

            if (dockingWindow is ToolWindow)
            {
                var descendents = VisualTreeHelperExtended.GetAllDescendants(_dockSite, typeof(SplitContainer));
                foreach (SplitContainer splitContainer in descendents)
                {
                    splitContainer.ResizeSlots(2.1, 7.9);
                }
            }
        }
Example #12
0
        /// <summary>
        /// Occurs when the <c>Layout.EvenlyDistributeDocumentsOnly</c> menu item is clicked.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param>
        private void OnLayoutEvenlyDistributeDocumentsOnlyMenuItemClick(object sender, RoutedEventArgs e)
        {
            var workspace = dockSite.PrimaryDockHost.Workspace;

            if (workspace != null)
            {
                var descendents = VisualTreeHelperExtended.GetAllDescendants <SplitContainer>(workspace);
                if (descendents != null)
                {
                    foreach (var splitContainer in descendents)
                    {
                        splitContainer.ResizeSlots();
                    }
                }
            }
        }
Example #13
0
        /// <summary>
        /// Occurs when the <c>Layout.EvenlyDistributeToolsOnly</c> menu item is clicked.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param>
        private void OnLayoutEvenlyDistributeToolsOnlyMenuItemClick(object sender, RoutedEventArgs e)
        {
            var descendents = VisualTreeHelperExtended.GetAllDescendants <SplitContainer>(dockSite);

            if (descendents != null)
            {
                foreach (var splitContainer in descendents)
                {
                    if (VisualTreeHelperExtended.GetAncestor <Workspace>(splitContainer) != null)
                    {
                        continue;
                    }

                    splitContainer.ResizeSlots();
                }
            }
        }
Example #14
0
        /// <summary>
        /// Occurs when the <c>Layout.RandomlyDistribute</c> menu item is clicked.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param>
        private void OnLayoutRandomlyDistributeMenuItemClick(object sender, RoutedEventArgs e)
        {
            var descendents = VisualTreeHelperExtended.GetAllDescendants <SplitContainer>(dockSite);

            if (descendents != null)
            {
                var random = new Random();
                foreach (var splitContainer in descendents)
                {
                    splitContainer.ResizeSlots(
                        random.NextDouble() * 8 + 1,
                        random.NextDouble() * 6 + 1,
                        random.NextDouble() * 4 + 1,
                        random.NextDouble() * 2 + 1);
                }
            }
        }
Example #15
0
        private static void OnDataGridRowMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DataGridRow row = sender as DataGridRow;

            if (null == row)
            {
                return;
            }

            DataGridControl datagrid = VisualTreeHelperExtended.GetAncestor(row, typeof(DataGridControl)) as DataGridControl;

            if (null == datagrid)
            {
                return;
            }

            if (CollectionView.NewItemPlaceholder == row.Item)
            {
                ControlTemplate template = GetTemplate(datagrid);
                if (row.Template == template)
                {
                    row.Template = GetDefaultTemplate(datagrid);
                    row.UpdateLayout();

                    datagrid.CurrentItem = row.Item;

                    // 3/23/2010 - Get the first non-read only column (http://www.actiprosoftware.com/Support/Forums/ViewForumTopic.aspx?ForumTopicID=4710)
                    DataGridColumn column = datagrid.Columns.FirstOrDefault(col => !col.IsReadOnly);
                    if (column != null)
                    {
                        DataGridCell cell = VisualTreeHelperExtended.GetAncestor(column.GetCellContent(row), typeof(DataGridCell)) as DataGridCell;

                        if (cell != null)
                        {
                            cell.Focus();
                        }
                    }

                    datagrid.BeginEdit();
                }
            }
        }
Example #16
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // COMMAND HANDLERS
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Occurs when the <see cref="RoutedCommand"/> is executed.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">An <see cref="ExecutedRoutedEventArgs"/> that contains the event data.</param>
        private void applicationExitCommand_Execute(object sender, ExecutedRoutedEventArgs e)
        {
            if (BrowserInteropHelper.IsBrowserHosted)
            {
                Page currentPage = (Page)VisualTreeHelperExtended.GetAncestor(this, typeof(Page));
                if ((currentPage != null) && (currentPage.NavigationService.CanGoBack))
                {
                    currentPage.NavigationService.Navigate(Application.Current.StartupUri);
                }
                else
                {
                    MessageBox.Show("Exit the application here.");
                }
            }
            else
            {
                Window window = (Window)ActiproSoftware.Windows.Media.VisualTreeHelperExtended.GetAncestor(ribbon, typeof(Window));
                if (window != null)
                {
                    window.Close();
                }
            }
        }
Example #17
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        #region COMMAND HANDLERS
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Occurs when the <see cref="RoutedCommand"/> is executed.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">An <see cref="ExecutedRoutedEventArgs"/> that contains the event data.</param>
        private static void OnToggleFrozenColumnExecute(object sender, ExecutedRoutedEventArgs e)
        {
            DataGridColumnHeader header = e.Parameter as DataGridColumnHeader;

            if (null != header)
            {
                DataGridControl datagrid = VisualTreeHelperExtended.GetAncestor(header, typeof(DataGridControl)) as DataGridControl;
                DataGridColumn  column   = header.Column;
                if (null != datagrid && null != column)
                {
                    if (column.IsFrozen)
                    {
                        // Need to unfreeze column
                        datagrid.FrozenColumnCount = column.DisplayIndex = datagrid.FrozenColumnCount - 1;
                    }
                    else
                    {
                        // Need to freeze column
                        column.DisplayIndex = datagrid.FrozenColumnCount++;
                    }
                }
            }
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // NON-PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Occurs when a tab is closing.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">A <see cref="AdvancedTabItemEventArgs"/> that contains the event data.</param>
        private void OnTabControlTabClosing(object sender, AdvancedTabItemEventArgs e)
        {
            var view = VisualTreeHelperExtended.GetAncestor <EditorView>(this);

            if (view == null)
            {
                return;
            }

            var tag = this.Tag as IntraLineViewportTag;

            if (tag == null)
            {
                return;
            }

            // Remove the tag
            IntraLineViewportTagger tagger = null;

            if (view.Properties.TryGetValue(typeof(IntraLineViewportTagger), out tagger))
            {
                tagger.Remove(tag);
            }
        }
Example #19
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // NON-PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Called when <c>Validation.Error</c> is fired on the PropertyGrid or one it's descendents.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ValidationErrorEventArgs"/> instance containing the event data.</param>
        private void OnPropertyGridValidationError(object sender, ValidationErrorEventArgs e)
        {
            switch (e.Action)
            {
            case ValidationErrorEventAction.Added:
                errorListBox.Items.Add(e.Error);

                // As a demonstration, show a dialog with the error message for property 'ErrorReporting3'
                var container = VisualTreeHelperExtended.GetAncestor <PropertyGridItem>(e.OriginalSource as DependencyObject);
                if (container != null)
                {
                    var propertyModel = container.Content as IPropertyModel;
                    if ((propertyModel != null) && (propertyModel.Name == "ErrorReporting3"))
                    {
                        MessageBox.Show(Convert.ToString(e.Error.ErrorContent, CultureInfo.CurrentCulture), "Data Validation", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                break;

            case ValidationErrorEventAction.Removed:
                errorListBox.Items.Add(e.Error);
                break;
            }
        }