Ejemplo n.º 1
1
 public void BackgroundSetThroughCode()
 {
     GridSplitter splitter = new GridSplitter();
     Brush b = new SolidColorBrush(Colors.Black);
     splitter.Background = b;
     Assert.AreEqual(b, splitter.GetValue(GridSplitter.BackgroundProperty), "Setting Background property should set backing dependency property.");
 }
Ejemplo n.º 2
0
        // Given:
        //static Dictionary<DependencyObject, GridLength> oldValues = new Dictionary<DependencyObject, GridLength>();
        private static void UpdateGrid(Grid grid, GridSplitter gridSplitter, bool newValue, bool oldValue, double heightRatio)
        {
            if (newValue)
            {
                // We're visible again
                switch (gridSplitter.ResizeDirection)
                {
                case GridResizeDirection.Columns:
                    break;

                case GridResizeDirection.Rows:
                    int ridx = (int)gridSplitter.GetValue(Grid.RowProperty);
                    var prev = grid.RowDefinitions.ElementAt(GetPrevious(gridSplitter, ridx));
                    var curr = grid.RowDefinitions.ElementAt(GetNext(gridSplitter, ridx));
                    //if (oldValues.ContainsKey(prev) && oldValues.ContainsKey(curr))
                    //{
                    //    prev.Height = oldValues[prev];
                    //    curr.Height = oldValues[curr];
                    //}

                    var prevHeight    = prev.Height.Value;
                    var newPrevHeight = prevHeight * (1 / (1 + heightRatio));
                    var newNextHeight = newPrevHeight * heightRatio;
                    System.Diagnostics.Debug.WriteLine($"PrevHeight: {prevHeight} NewPrevHeight: {newPrevHeight} NewNextHeight: {newNextHeight}");
                    var prevUnits = prev.Height.GridUnitType;
                    prev.Height = new GridLength(newPrevHeight, prevUnits);
                    curr.Height = new GridLength(newNextHeight, prevUnits);

                    break;
                }
            }
            else
            {
                // We're being hidden
                switch (gridSplitter.ResizeDirection)
                {
                case GridResizeDirection.Columns:
                    break;

                case GridResizeDirection.Rows:
                    int ridx = (int)gridSplitter.GetValue(Grid.RowProperty);
                    var prev = grid.RowDefinitions.ElementAt(GetPrevious(gridSplitter, ridx));
                    var curr = grid.RowDefinitions.ElementAt(GetNext(gridSplitter, ridx));
                    switch (gridSplitter.ResizeBehavior)
                    {
                    // Naively assumes only one type of collapsing!
                    case GridResizeBehavior.PreviousAndNext:
                    case GridResizeBehavior.PreviousAndCurrent:
                        //oldValues[prev] = prev.Height;
                        // add both heights to the previous grid row
                        prev.Height = new GridLength(prev.Height.Value + curr.Height.Value, prev.Height.GridUnitType);           // new GridLength(1.0, GridUnitType.Star);

                        //oldValues[curr] = curr.Height;
                        curr.Height = new GridLength(0.0);
                        break;
                    }
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public void IsEnabledSetThroughCode()
        {
            GridSplitter splitter = new GridSplitter();

            splitter.IsEnabled = false;
            Assert.AreEqual(false, splitter.GetValue(GridSplitter.IsEnabledProperty), "Setting IsEnabled property should set backing dependency property.");
        }
Ejemplo n.º 4
0
        public void ShowsPreviewSetThroughCode()
        {
            GridSplitter splitter = new GridSplitter();

            splitter.ShowsPreview = false;
            Assert.AreEqual(false, splitter.GetValue(GridSplitter.ShowsPreviewProperty), "Setting ShowsPreview property should set backing dependency property.");
        }
Ejemplo n.º 5
0
        private static int GetIndex(this GridSplitter gridSplitter)
        {
            var index = -1;

            switch (gridSplitter.GetResizeDirection())
            {
            case GridResizeDirection.Columns:
                index = (int)gridSplitter.GetValue(Grid.ColumnProperty);
                break;

            case GridResizeDirection.Rows:
                index = (int)gridSplitter.GetValue(Grid.RowProperty);
                break;
            }
            return(index);
        }
Ejemplo n.º 6
0
        private void gs_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
        {
            GridSplitter gs = sender as GridSplitter;

            if (gs != null)
            {
                int columnIndex = (int)gs.GetValue(Grid.ColumnProperty);

                Table table = gs.Tag as Table;
                if (table != null)
                {
                    if (e.HorizontalChange > 0 || Math.Abs(e.HorizontalChange) < table.Columns[columnIndex].Width.Value)
                    {
                        table.Columns[columnIndex].Width = new GridLength(table.Columns[columnIndex].Width.Value + e.HorizontalChange);
                    }

                    Grid grid = this.RTBCanvas.Children[this.RTBCanvas.Children.Count - 1] as Grid;

                    if (grid != null)
                    {
                        this.RTBCanvas.Children.Remove(grid);
                        grid.Visibility = Visibility.Hidden;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void BackgroundSetThroughCode()
        {
            GridSplitter splitter = new GridSplitter();
            Brush        b        = new SolidColorBrush(Colors.Black);

            splitter.Background = b;
            Assert.AreEqual(b, splitter.GetValue(GridSplitter.BackgroundProperty), "Setting Background property should set backing dependency property.");
        }
Ejemplo n.º 8
0
        public void PreviewStyleSetThroughCode()
        {
            GridSplitter splitter = new GridSplitter();
            Style        s        = new Style(typeof(PreviewControl));

            splitter.PreviewStyle = s;
            Assert.AreEqual(s, splitter.GetValue(GridSplitter.PreviewStyleProperty), "Setting PreviewStyle property should set backing dependency property.");
        }
Ejemplo n.º 9
0
        public void HorizontalHandleStyleSetViaCode()
        {
            GridSplitter splitter = new GridSplitter();
            Style        s        = new Style(typeof(System.Windows.Controls.Primitives.ToggleButton));

            splitter.HorizontalHandleStyle = s;
            Assert.AreEqual(s, splitter.GetValue(GridSplitter.HorizontalHandleStyleProperty), "Assigning a new style to the HandleStyleProperty should set the style.");
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Collapses or expands the parent view's splitter for current view
        /// </summary>
        /// <param name="collapsed">True to collapse, false to expand</param>
        protected virtual void CollapseParentSplitter(bool collapsed)
        {
            FrameworkElement panel = Parent as FrameworkElement;
            Grid             grid  = panel == null ? null : panel.Parent as Grid;

            if (panel == null)
            {
                return;                // no grid or parent
            }
            int?col = panel.GetValue(Grid.ColumnProperty) as int?;

            if (col == null || grid.ColumnDefinitions.Count < col)
            {
                return;                                                    // invalid column
            }
            if (collapsed)
            {
                grid.ColumnDefinitions[col.Value].Width = new GridLength(0);
            }
            else if (grid.ColumnDefinitions[col.Value].Width.Value == 0)
            {
                grid.ColumnDefinitions[col.Value].Width = GridLength.Auto;
            }

            // find the splitter for the parent panel
            GridSplitter splitter = null;

            foreach (DependencyObject child in grid.Children)
            {
                GridSplitter sp = child as GridSplitter;
                if (sp == null)
                {
                    continue;
                }
                else if (splitter == null)
                {
                    splitter = sp;
                    continue;
                }
                // more than one splitter in the parent grid -> get the closest one
                int?spCol       = sp.GetValue(Grid.ColumnProperty) as int?;
                int?splitterCol = splitter.GetValue(Grid.ColumnProperty) as int?;
                if (spCol == null)
                {
                    continue;
                }
                if (splitterCol == null || Math.Abs(col.Value - spCol.Value) < Math.Abs(col.Value - splitterCol.Value))
                {
                    splitter = sp;
                }
            }
            if (splitter != null)
            {
                splitter.Visibility = collapsed ? Visibility.Collapsed : Visibility.Visible;
            }
        }
Ejemplo n.º 11
0
        private void onColapseClick(object sender, MouseButtonEventArgs e)
        {
            GridSplitter splitter = sender as GridSplitter;
            Grid         grid     = splitter.Parent as Grid;
            //get the first column (0)
            int        colIndex      = (int)splitter.GetValue(Grid.ColumnProperty);
            GridLength gridWidth     = grid.ColumnDefinitions[colIndex].Width;
            GridLength splitterWidth = new GridLength(splitter.Width);

            if (gridWidth == splitterWidth)
            {
                //expand
                grid.ColumnDefinitions[colIndex].Width = cachedColumnWidth;
            }
            else
            {
                //colapse
                cachedColumnWidth = gridWidth;
                grid.ColumnDefinitions[colIndex].Width = splitterWidth;
            }
        }
Ejemplo n.º 12
0
 public void IsEnabledSetThroughCode()
 {
     GridSplitter splitter = new GridSplitter();
     splitter.IsEnabled = false;
     Assert.AreEqual(false, splitter.GetValue(GridSplitter.IsEnabledProperty), "Setting IsEnabled property should set backing dependency property.");
 }
Ejemplo n.º 13
0
 public void PreviewStyleSetThroughCode()
 {
     GridSplitter splitter = new GridSplitter();
     Style s = new Style(typeof(PreviewControl));
     splitter.PreviewStyle = s;
     Assert.AreEqual(s, splitter.GetValue(GridSplitter.PreviewStyleProperty), "Setting PreviewStyle property should set backing dependency property.");
 }
Ejemplo n.º 14
0
 public void ShowsPreviewSetThroughCode()
 {
     GridSplitter splitter = new GridSplitter();
     splitter.ShowsPreview = false;
     Assert.AreEqual(false, splitter.GetValue(GridSplitter.ShowsPreviewProperty), "Setting ShowsPreview property should set backing dependency property.");
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Gets the row to hide if the <see cref="GridSplitter"/> is hidden.
 /// </summary>
 public static int GetHidesRow(GridSplitter target)
 {
     return((int)target.GetValue(HidesRowProperty));
 }